Check-in [227c179b06]
Overview
Comment:Updated to allow (and require) user to specify timeout
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:227c179b064b6689bb49f7429e85ef7add5cab57
User & Date: rkeene on 2012-09-09 21:25:04
Other Links: manifest | tags
Context
2012-09-09
21:25
Corrected example in test.tcl check-in: 2c31ced898 user: rkeene tags: trunk
21:25
Updated to allow (and require) user to specify timeout check-in: 227c179b06 user: rkeene tags: trunk
21:18
Started processing "umask" and "cwd" arguments Updated to have 30sec (currently hard-coded) timeout for starting processes check-in: 270bafa39f user: rkeene tags: trunk
Changes

Modified initrd/admin-tclkit/kitcreator-modules/system/build-dyn.sh from [078554ca42] to [3cc9484186].

     4      4   . build-common.sh
     5      5   
     6      6   # Compile using the same options as Tcl
     7      7   TCLCONFIGSH="$(find /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 /lib /lib64 -name tclConfig.sh -print -quit)"
     8      8   
     9      9   . "${TCLCONFIGSH}"
    10     10   
    11         -echo "${TCL_CC} -fPIC -DPIC -Wall -DUSE_TCL_STUBS=1 ${TCL_DEFS} ${TCL_INCLUDE_SPEC} ${TCL_STUB_LIB_SPEC} -shared -rdynamic -o system.so system.c"
    12         -eval ${TCL_CC} -fPIC -DPIC -Wall -DUSE_TCL_STUBS=1 ${TCL_DEFS} ${TCL_INCLUDE_SPEC} ${TCL_STUB_LIB_SPEC} -shared -rdynamic -o system.so system.c
           11  +echo "${TCL_CC} -ggdb3 -fPIC -DPIC -Wall -DUSE_TCL_STUBS=1 ${TCL_DEFS} ${TCL_INCLUDE_SPEC} ${TCL_STUB_LIB_SPEC} -shared -rdynamic -o system.so system.c"
           12  +eval ${TCL_CC} -ggdb3 -fPIC -DPIC -Wall -DUSE_TCL_STUBS=1 ${TCL_DEFS} ${TCL_INCLUDE_SPEC} ${TCL_STUB_LIB_SPEC} -shared -rdynamic -o system.so system.c

Modified initrd/admin-tclkit/kitcreator-modules/system/system.c from [dc2605a233] to [1d6aabc455].

     1      1   #define _LINUX_SOURCE 1
     2      2   #include <sys/syscall.h>
     3      3   #include <netinet/in.h>
     4      4   #include <arpa/inet.h>
     5      5   #include <sys/socket.h>
            6  +#include <sys/select.h>
     6      7   #include <sys/mount.h>
     7      8   #include <sys/types.h>
     8      9   #include <sys/ioctl.h>
     9     10   #include <sys/swap.h>
    10     11   #include <sys/stat.h>
    11     12   #include <sys/wait.h>
    12     13   #include <stdlib.h>
................................................................................
  1875   1876   	}
  1876   1877   
  1877   1878   	return(retval);
  1878   1879   }
  1879   1880   
  1880   1881   static int tclsystem_tsmf_start_svc(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
  1881   1882   	struct timeval select_timeout;
  1882         -	Tcl_WideInt umask_tclval;
  1883         -	Tcl_Obj *filename_obj, *env_obj, *logfile_obj, **env_entry_objv, *cwd_obj, *umask_obj, *user_obj, *group_obj, *sri_obj;
         1883  +	Tcl_WideInt umask_val, timeout_val;
         1884  +	Tcl_Obj *filename_obj, *env_obj, *logfile_obj, **env_entry_objv, *cwd_obj, *umask_obj, *user_obj, *group_obj;
         1885  +	Tcl_Obj *sri_obj, *timeout_obj;
  1884   1886   	pid_t child, child_pgid = -1;
  1885   1887   	ssize_t read_ret;
  1886   1888   	time_t currtime;
  1887         -	mode_t umask_val;
  1888   1889   	char *argv[3], *envv[512];
  1889   1890   	char *logfile, *filename, *cwd, *user, *group;
  1890   1891   	char logmsg[2048];
  1891   1892   	fd_set read_fdset;
  1892   1893   	int pipe_ret, setsid_ret, execve_ret, tcl_ret, select_ret;
  1893   1894   	int null_fd, log_fd, tmp_fd, max_fd;
  1894   1895   	int env_entry_objc;
  1895   1896   	int fds[2], fd;
  1896   1897   	int status;
  1897   1898   	int idx;
  1898   1899   
  1899   1900   	/* 1. Parse arguments */
  1900   1901   	/* 1.a. Ensure the correct number of arguments were passed */
  1901         -	if (objc != 9) {
  1902         -		Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args: should be \"::system::syscall::tsmf_start_svc sri filename logfile env cwd umask user group\"", -1));
         1902  +	if (objc != 10) {
         1903  +		Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args: should be \"::system::syscall::tsmf_start_svc sri filename logfile env cwd umask user group timeout\"", -1));
  1903   1904   
  1904   1905   		return(TCL_ERROR);
  1905   1906   	}
  1906   1907   
  1907   1908   	/* 1.b. Identify Tcl_Objs to use for each argument */
  1908   1909   	sri_obj = objv[1];
  1909   1910   	filename_obj = objv[2];
  1910   1911   	logfile_obj = objv[3];
  1911   1912   	env_obj = objv[4];
  1912   1913   	cwd_obj = objv[5];
  1913   1914   	umask_obj = objv[6];
  1914   1915   	user_obj = objv[7];
  1915   1916   	group_obj = objv[8];
         1917  +	timeout_obj = objv[9];
  1916   1918   
  1917   1919   	/* 1.c. Store string arguments */
  1918   1920   	filename = Tcl_GetString(filename_obj);
  1919   1921   	logfile = Tcl_GetString(logfile_obj);
  1920   1922   	cwd = Tcl_GetString(cwd_obj);
  1921   1923   	user = Tcl_GetString(user_obj);
  1922   1924   	group = Tcl_GetString(group_obj);
  1923   1925   
  1924   1926   	/* 1.d. Integer objects */
  1925         -	tcl_ret = Tcl_GetWideIntFromObj(interp, umask_obj, &umask_tclval);
         1927  +	tcl_ret = Tcl_GetWideIntFromObj(interp, umask_obj, &umask_val);
         1928  +	if (tcl_ret != TCL_OK) {
         1929  +		return(tcl_ret);
         1930  +	}
         1931  +
         1932  +	tcl_ret = Tcl_GetWideIntFromObj(interp, timeout_obj, &timeout_val);
  1926   1933   	if (tcl_ret != TCL_OK) {
  1927   1934   		return(tcl_ret);
  1928   1935   	}
  1929   1936   
  1930         -	umask_val = umask_tclval;
  1931         -
  1932   1937   	/* 1.e. Process environment */
  1933   1938   	tcl_ret = Tcl_ListObjGetElements(interp, env_obj, &env_entry_objc, &env_entry_objv);
  1934   1939   	if (tcl_ret != TCL_OK) {
  1935   1940   		return(tcl_ret);
  1936   1941   	}
  1937   1942   
  1938   1943   	for (idx = 0; idx < MIN(env_entry_objc, sizeof(envv) / sizeof(envv[0]) - 1); idx++) {
................................................................................
  1959   1964   	if (child != 0) {
  1960   1965   		/* 4.parent. Get PGID from child */
  1961   1966   		/* 4.parent.a. Close write end of pipe -- we are read-only */
  1962   1967   		close(fds[1]);
  1963   1968   		fd = fds[0];
  1964   1969   
  1965   1970   		/* 4.parent.b. Read process group ID of child from pipe */
  1966         -		select_timeout.tv_sec = 30;
         1971  +		select_timeout.tv_sec = timeout_val;
  1967   1972   		select_timeout.tv_usec = 0;
  1968   1973   
  1969   1974   		FD_ZERO(&read_fdset);
  1970   1975   		FD_SET(fd, &read_fdset);
  1971   1976   
  1972   1977   		select_ret = select(fd + 1, &read_fdset, NULL, NULL, &select_timeout);
  1973   1978   		if (select_ret == 0) {

Modified initrd/admin-tclkit/kitcreator-modules/system/test.tcl from [8645af428b] to [97fe9fd63b].

     1      1   #! /usr/bin/env tclsh
     2      2   
     3      3   puts [exec ./build-dyn.sh]
     4      4   
     5      5   load ./system.so
            6  +
            7  +::system::syscall::tsmf_start_svc blah /bin/true /tmp/logfile [list PATH=/bin] / 022 root root
     6      8   
     7      9   foreach iface [system::syscall::ifconfig] {
     8     10   #lo0:2: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
     9     11   #        inet 127.0.0.1 netmask ff000000 
    10     12   #aggr100003:1: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 2
    11     13   #        inet 140.194.100.149 netmask ffffff00 broadcast 140.194.100.255
    12     14