Annotation of OpenXM/src/kxx/oxlog.c, Revision 1.10
1.10 ! takayama 1: /*$OpenXM: OpenXM/src/kxx/oxlog.c,v 1.9 2001/05/06 07:53:00 takayama Exp $*/
1.1 maekawa 2: #include <stdio.h>
3: #include <signal.h>
1.3 takayama 4: #include <string.h>
5: #include <stdlib.h>
1.1 maekawa 6: #include <sys/types.h>
7: #include <sys/stat.h>
8: #include <fcntl.h>
9: /* In some distributions of linux you need to include the following file
10: #include <linux/sched.h>
11: */
12: #include <unistd.h>
13:
14: /* oxlog /usr/X11R6/bin/xterm -icon -e /home/nobuki/kxx/ox
15: 0 1 2 3 4
16: -ox /home/nobuki/kxx/ox_asir
17: 5 6
18: */
19: /* oxlog /home/nobuki/kxx/ox
20: 0 1
21: -ox /home/nobuki/kxx/ox_asir >& /dev/null
22: 2 3
23: */
1.6 takayama 24: static int Debug_which = 1;
1.10 ! takayama 25: extern char **environ;
1.8 ohara 26:
27: /*which("xterm", getenv("PATH"));*/
28: char *which(char *prog, char *path_env)
29: {
1.9 takayama 30: extern int Debug_which ;
31: char *tok;
32: char *path;
33: char delim[] = ":";
34: char *e = alloca(strlen(path_env)+1);
35: strcpy(e, path_env);
36: tok = strtok(e, delim);
37: if (Debug_which) {
38: fprintf(stderr, "PATH=%s\n", path_env);
39: }
40: while (tok != NULL) {
41: char *path = malloc(strlen(tok)+strlen(prog)+2);
42: sprintf(path, "%s/%s", tok, prog);
43: if (access(path, X_OK&R_OK) == 0) {
44: if (Debug_which) {
45: fprintf(stderr, "Found: %s\n", path);
46: }
47: return path;
1.8 ohara 48: }
1.9 takayama 49: free(path);
50: tok = strtok(NULL, delim);
51: }
52: return NULL;
1.3 takayama 53: }
54:
1.8 ohara 55: char *toFullPath(char *s)
56: {
1.9 takayama 57: extern int Debug_which;
58: char *path = "/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/openwin/bin:/usr/X/bin";
59: char *s2;
60: if (strlen(s) == 0 || strchr(s, '/') != NULL) {
61: return s;
62: }
63: s2 = which(s, getenv("PATH"));
64: if (s2 == NULL) {
65: if (Debug_which) {
66: fprintf(stderr, "Could not find arg[1] in your search path.\n");
67: fprintf(stderr, "You path is %s.\n", getenv("PATH"));
68: fprintf(stderr, "Trying to find in the path: %s\n", path);
1.8 ohara 69: }
1.9 takayama 70: s2 = which(s, path);
71: /* Why? */
72: }
73: return s2;
1.3 takayama 74: }
75:
1.8 ohara 76: int main(int argc, char *argv[])
1.3 takayama 77: {
1.9 takayama 78: sigset_t sss;
79: int i;
80: char *oxname;
81: /* char *env[2];
82: env[0] = NULL;*/
83: sigemptyset(&sss);
84: sigaddset(&sss, SIGINT);
85: sigprocmask(SIG_BLOCK, &sss, NULL);
86: if (argc >= 2) {
87: oxname = toFullPath(argv[1]);
88: if (oxname == NULL) {
89: oxname = "NULL";
90: } /* Why? */
1.10 ! takayama 91:
! 92: /*
! 93: {
! 94: int i;
! 95: i=0;
! 96: while (environ[i] != NULL) {
! 97: fprintf(stderr,"%s ",environ[i++]);
! 98: }
! 99: fprintf(stderr,"\n");
! 100: }
! 101: */
! 102:
! 103: execve(oxname, argv+1,environ);
1.8 ohara 104:
1.9 takayama 105: fprintf(stderr, "\nError in oxlog: Failed to start the process.\n");
106: fprintf(stderr, "oxname=%s\n", oxname);
107: for (i=0; i<argc; i++) {
108: fprintf(stderr, "argv[%d]=%s ", i, argv[i]);
109: }
110: fprintf(stderr, "\n");
111: exit(20);
112: }else {
113: fprintf(stderr, "Error in oxlog: cannot handle argc=%d\n", argc);
114: fprintf(stderr, "oxname=???\n");
115: for (i=0; i<argc; i++) {
116: fprintf(stderr, "argv[%d]=%s ", i, argv[i]);
1.3 takayama 117: }
1.9 takayama 118: fprintf(stderr, "\n");
119: fprintf(stderr, "Usage example 1: oxlog /usr/X11R6/bin/xterm -icon -e /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir\n");
120: fprintf(stderr, " example 2: oxlog /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir >& /dev/null\n");
121: exit(10);
122: }
1.1 maekawa 123: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>