Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Implemented user scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
RMerl committed Jun 19, 2012
1 parent 6505d96 commit dd76105
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
25 changes: 25 additions & 0 deletions release/src/router/rc/common.c
Expand Up @@ -1393,3 +1393,28 @@ void setup_dnsmq(int mode)
}
#endif

void run_custom_script(char *name)
{
char script[120];

sprintf(script, "/jffs/scripts/%s", name);

if(f_exists(script)) {
_dprintf("Script: running %s\n", script);
xstart(script);
}
}

void run_custom_script_blocking(char *name, char *args)
{
char script[120];

sprintf(script, "/jffs/scripts/%s", name);

if(f_exists(script)) {
_dprintf("Script: running %s\n", script);
eval(script, args);
}

}

2 changes: 2 additions & 0 deletions release/src/router/rc/firewall.c
Expand Up @@ -4120,6 +4120,8 @@ int start_firewall(int wanunit, int lanunit)
}
#endif

run_custom_script("firewall-start");

return 0;
}

Expand Down
4 changes: 4 additions & 0 deletions release/src/router/rc/services.c
Expand Up @@ -2368,6 +2368,8 @@ start_services(void)
start_webdav();
#endif

run_custom_script("services-start");

return 0;
}

Expand All @@ -2384,6 +2386,8 @@ void
stop_services(void)
{

run_custom_script("services-stop");

#ifdef RTCONFIG_WEBDAV
stop_webdav();
#endif
Expand Down
3 changes: 3 additions & 0 deletions release/src/router/rc/usb.c
Expand Up @@ -838,6 +838,8 @@ int mount_partition(char *dev_name, int host_num, char *dsc_name, char *pt_name,
if(!is_valid_hostname(the_label))
memset(the_label, 0, 128);

run_custom_script_blocking("pre-mount", dev_name);

if (f_exists("/etc/fstab")) {
if (strcmp(type, "swap") == 0) {
_eval(swp_argv, NULL, 0, NULL);
Expand Down Expand Up @@ -1064,6 +1066,7 @@ _dprintf("cloudsync: finished.\n");
start_cloudsync();
}
#endif
run_custom_script_blocking("post-mount", mountpoint);
}
return (ret == MOUNT_VAL_RONLY || ret == MOUNT_VAL_RW);
}
Expand Down
3 changes: 3 additions & 0 deletions release/src/router/rc/wan.c
Expand Up @@ -750,6 +750,9 @@ void update_wan_state(char *prefix, int state, int reason)
// keep ip info if it is stopped from connected
nvram_set_int(strcat_r(prefix, "sbstate_t", tmp), reason);
}
else if (state == WAN_STATE_CONNECTED) {
run_custom_script("wan-start");
}
}

#ifdef RTCONFIG_IPV6
Expand Down

0 comments on commit dd76105

Please sign in to comment.