Check-in [2fe4c86606]
Overview
SHA1:2fe4c866062717e3a0734ae62b0a707ca38c4d1a
Date: 2014-12-23 06:19:34
User: rkeene
Comment:Updated to include more logs for TSMF starter
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2014-12-23
08:05
[9839015dcd] Added a simple "waitpid" implementation (user: rkeene, tags: trunk)
06:19
[2fe4c86606] Updated to include more logs for TSMF starter (user: rkeene, tags: trunk)
2014-12-22
20:12
[e1d82ef47f] Updated to reverse the order of dependencies, as appears to be done in the modules.dep file (user: rkeene, tags: trunk)
Changes

Modified tuapi.c from [2fd850bfb1] to [3b213ed76e].

  2743   2743   		Tcl_SetObjResult(interp, Tcl_NewStringObj("fork failed", -1));
  2744   2744   
  2745   2745   		return(TCL_ERROR);
  2746   2746   	}
  2747   2747   
  2748   2748   	if (child != 0) {
  2749   2749   		/* 4.parent. Get PGID from child */
  2750         -		/* 4.parent.a. Close write end of pipe -- we are read-only */
         2750  +		/* 4.parent.a. Open log file */
         2751  +		log_fd = open(logfile, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
         2752  +
         2753  +		/* 4.parent.b. Close write end of pipe -- we are read-only */
  2751   2754   		close(fds[1]);
  2752   2755   		fd = fds[0];
  2753   2756   
  2754         -		/* 4.parent.b. Read process group ID of child from pipe */
         2757  +		/* 4.parent.c. Read process group ID of child from pipe */
  2755   2758   		select_timeout.tv_sec = timeout_val;
  2756   2759   		select_timeout.tv_usec = 0;
  2757   2760   
  2758   2761   		FD_ZERO(&read_fdset);
  2759   2762   		FD_SET(fd, &read_fdset);
  2760   2763   
  2761   2764   		select_ret = select(fd + 1, &read_fdset, NULL, NULL, &select_timeout);
................................................................................
  2763   2766   			/* On timeout, terminate starting process */
  2764   2767   			child_pgid = getpgid(child);
  2765   2768   			if (child_pgid != -1) {
  2766   2769   				kill(-child_pgid, SIGKILL);
  2767   2770   			}
  2768   2771   
  2769   2772   			Tcl_SetObjResult(interp, Tcl_NewStringObj("timeout", -1));
         2773  +
         2774  +			currtime = time(NULL);
         2775  +			strftime(logmsg, sizeof(logmsg), "[ %b %e %H:%M:%S ", localtime(&currtime));
         2776  +			write(log_fd, logmsg, strlen(logmsg));
         2777  +
         2778  +			snprintf(logmsg, sizeof(logmsg), "Method \"start\" timed out after %i seconds ]\n", (int) timeout_val);
         2779  +			write(log_fd, logmsg, strlen(logmsg));
         2780  +
         2781  +			close(log_fd);
  2770   2782   
  2771   2783   			return(TCL_ERROR);
  2772   2784   		}
  2773   2785   
  2774   2786   		if (select_ret > 0) {
  2775   2787   			read_ret = read(fd, &child_pgid, sizeof(child_pgid));
  2776   2788   		}
  2777   2789   
  2778         -		/* 4.parent.c. Close read end of pipe */
         2790  +		/* 4.parent.d. Close read end of pipe */
  2779   2791   		close(fd);
  2780   2792   
  2781         -		/* 4.parent.d. Verify read was meaningful */
         2793  +		/* 4.parent.e. Verify read was meaningful */
  2782   2794   		if (read_ret != sizeof(child_pgid)) {
  2783   2795   			Tcl_SetObjResult(interp, Tcl_NewStringObj("failed to communicate with started service", -1));
         2796  +
         2797  +			currtime = time(NULL);
         2798  +			strftime(logmsg, sizeof(logmsg), "[ %b %e %H:%M:%S ", localtime(&currtime));
         2799  +			write(log_fd, logmsg, strlen(logmsg));
         2800  +
         2801  +			snprintf(logmsg, sizeof(logmsg), "Method \"start\" failed: communication with started service broken ]\n");
         2802  +			write(log_fd, logmsg, strlen(logmsg));
         2803  +
         2804  +			close(log_fd);
  2784   2805   
  2785   2806   			return(TCL_ERROR);
  2786   2807   		}
  2787   2808   
  2788         -		/* 4.parent.e. If the PGID given is actually an error, return error */
         2809  +		/* 4.parent.f. If the PGID given is actually an error, return error */
  2789   2810   		if (child_pgid == -1) {
  2790   2811   			Tcl_SetObjResult(interp, Tcl_NewStringObj("service failed to start", -1));
         2812  +
         2813  +			currtime = time(NULL);
         2814  +			strftime(logmsg, sizeof(logmsg), "[ %b %e %H:%M:%S ", localtime(&currtime));
         2815  +			write(log_fd, logmsg, strlen(logmsg));
         2816  +
         2817  +			snprintf(logmsg, sizeof(logmsg), "Method \"start\" failed ]\n");
         2818  +			write(log_fd, logmsg, strlen(logmsg));
         2819  +
         2820  +			close(log_fd);
  2791   2821   
  2792   2822   			return(TCL_ERROR);
  2793   2823   		}
  2794   2824   
  2795         -		/* 4.parent.f. Return PGID to Tcl */
         2825  +		/* 4.parent.g. Return PGID to Tcl */
  2796   2826   		Tcl_SetObjResult(interp, Tcl_NewWideIntObj((Tcl_WideInt) child_pgid));
         2827  +
         2828  +		currtime = time(NULL);
         2829  +		strftime(logmsg, sizeof(logmsg), "[ %b %e %H:%M:%S ", localtime(&currtime));
         2830  +		write(log_fd, logmsg, strlen(logmsg));
         2831  +
         2832  +		snprintf(logmsg, sizeof(logmsg), "Method \"start\" completed, process group = %lu ]\n", (unsigned long) child_pgid);
         2833  +		write(log_fd, logmsg, strlen(logmsg));
         2834  +
         2835  +		close(log_fd);
  2797   2836   
  2798   2837   		return(TCL_OK);
  2799   2838   	}
  2800   2839   
  2801   2840   	/* 4.child.a. Close read end of pipe -- we only write to it */
  2802   2841   	close(fds[0]);
  2803   2842   	fd = fds[1];