- snprintf(tmp, 64, "%s%s", uci_path, name);
- snprintf(tmp2, 64, "/tmp/run/mountd/%s", dev);
- symlink(tmp2, tmp);
- mount_new("/tmp/run/mountd/", dev);
+
+ snprintf(dev_link, sizeof(dev_link), "%s%s", uci_path, name);
+ snprintf(dev_path, sizeof(dev_path), "%s%s", "/tmp/run/mountd/", dev);
+ /* If link aleady exists - replace it */
+ if (lstat(dev_link, &st) == 0 && S_ISLNK(st.st_mode)) {
+ snprintf(tmp, sizeof(tmp), "%s%s", uci_path, "tmp");
+ symlink(dev_path, tmp);
+ rename(tmp, dev_link);
+ } else {
+ symlink(dev_path, dev_link);
+ }
+ if (!mount_new("/tmp/run/mountd/", dev))
+ system_printf("ACTION=add DEVICE=%s NAME=%s /sbin/hotplug-call mount", dev, name);