Check-in [e91caa4ecf]
Overview
Comment:Removed unneeded casts
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e91caa4ecf411f7e9d97bf2e3a8a7b6dfce9a00a
User & Date: rkeene on 2012-09-15 06:53:41
Other Links: manifest | tags
Context
2012-09-17
13:23
Updated to use uid/gid instead of usernames check-in: 1e1d242f28 user: rkeene tags: trunk
2012-09-15
06:53
Removed unneeded casts check-in: e91caa4ecf user: rkeene tags: trunk
06:48
Updated to check return value of chdir() check-in: ecc5931c14 user: rkeene tags: trunk
Changes

Modified system.c from [7d48c39a12] to [2a84d834a9].

1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
		Tcl_SetObjResult(interp, Tcl_NewStringObj("pipe failed", -1));

		return(TCL_ERROR);
	}

	/* 3. Fork into a new process */
	child = fork();
	if (child == ((pid_t) -1)) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj("fork failed", -1));

		return(TCL_ERROR);
	}

	if (child != 0) {
		/* 4.parent. Get PGID from child */







|







1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
		Tcl_SetObjResult(interp, Tcl_NewStringObj("pipe failed", -1));

		return(TCL_ERROR);
	}

	/* 3. Fork into a new process */
	child = fork();
	if (child == -1) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj("fork failed", -1));

		return(TCL_ERROR);
	}

	if (child != 0) {
		/* 4.parent. Get PGID from child */
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
		FD_ZERO(&read_fdset);
		FD_SET(fd, &read_fdset);

		select_ret = select(fd + 1, &read_fdset, NULL, NULL, &select_timeout);
		if (select_ret == 0) {
			/* On timeout, terminate starting process */
			child_pgid = getpgid(child);
			if (child_pgid != ((pid_t) -1)) {
				kill(-child_pgid, SIGKILL);
			}

			Tcl_SetObjResult(interp, Tcl_NewStringObj("timeout", -1));

			return(TCL_ERROR);
		}







|







1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
		FD_ZERO(&read_fdset);
		FD_SET(fd, &read_fdset);

		select_ret = select(fd + 1, &read_fdset, NULL, NULL, &select_timeout);
		if (select_ret == 0) {
			/* On timeout, terminate starting process */
			child_pgid = getpgid(child);
			if (child_pgid != -1) {
				kill(-child_pgid, SIGKILL);
			}

			Tcl_SetObjResult(interp, Tcl_NewStringObj("timeout", -1));

			return(TCL_ERROR);
		}
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
		if (read_ret != sizeof(child_pgid)) {
			Tcl_SetObjResult(interp, Tcl_NewStringObj("failed to communicate with started service", -1));

			return(TCL_ERROR);
		}

		/* 4.parent.e. If the PGID given is actually an error, return error */
		if (child_pgid == ((pid_t) -1)) {
			Tcl_SetObjResult(interp, Tcl_NewStringObj("service failed to start", -1));

			return(TCL_ERROR);
		}

		/* 4.parent.f. Return PGID to Tcl */
		Tcl_SetObjResult(interp, Tcl_NewWideIntObj((Tcl_WideInt) child_pgid));

		return(TCL_OK);
	}

	/* 4.child.a. Close read end of pipe -- we only write to it */
	close(fds[0]);
	fd = fds[1];

	/* 5. Create a new session */
	setsid_ret = setsid();
	if (setsid_ret == ((pid_t) -1)) {
		write(fd, &child_pgid, sizeof(child_pgid));

		_exit(0);
	}

	/* 6. Setup environment */
	/* 6.a. Set umask */







|

















|







1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
		if (read_ret != sizeof(child_pgid)) {
			Tcl_SetObjResult(interp, Tcl_NewStringObj("failed to communicate with started service", -1));

			return(TCL_ERROR);
		}

		/* 4.parent.e. If the PGID given is actually an error, return error */
		if (child_pgid == -1) {
			Tcl_SetObjResult(interp, Tcl_NewStringObj("service failed to start", -1));

			return(TCL_ERROR);
		}

		/* 4.parent.f. Return PGID to Tcl */
		Tcl_SetObjResult(interp, Tcl_NewWideIntObj((Tcl_WideInt) child_pgid));

		return(TCL_OK);
	}

	/* 4.child.a. Close read end of pipe -- we only write to it */
	close(fds[0]);
	fd = fds[1];

	/* 5. Create a new session */
	setsid_ret = setsid();
	if (setsid_ret == -1) {
		write(fd, &child_pgid, sizeof(child_pgid));

		_exit(0);
	}

	/* 6. Setup environment */
	/* 6.a. Set umask */
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
	/* XXX: TODO */

	/* 6.g.ii. User */
	/* XXX: TODO */

	/* 7. Create a new process to actually spawn the process */
	child = fork();
	if (child == ((pid_t) -1)) {
		write(fd, &child_pgid, sizeof(child_pgid));

		_exit(0);
	}

	if (child != 0) {
		/* 7.parent.a. Wait for child process to terminate and collect status */
		waitpid_ret = waitpid(child, &status, 0);
		if (waitpid_ret == ((pid_t) -1)) {
			status = -1;
		}

		/* 7.parent.b. Set PGID (if successful, -1 otherwise) to pass back to TSMF */
		if (status == 0) {
			child_pgid = getpgid(getpid());
		}







|








|







2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
	/* XXX: TODO */

	/* 6.g.ii. User */
	/* XXX: TODO */

	/* 7. Create a new process to actually spawn the process */
	child = fork();
	if (child == -1) {
		write(fd, &child_pgid, sizeof(child_pgid));

		_exit(0);
	}

	if (child != 0) {
		/* 7.parent.a. Wait for child process to terminate and collect status */
		waitpid_ret = waitpid(child, &status, 0);
		if (waitpid_ret == -1) {
			status = -1;
		}

		/* 7.parent.b. Set PGID (if successful, -1 otherwise) to pass back to TSMF */
		if (status == 0) {
			child_pgid = getpgid(getpid());
		}