Changeset 3857 for trunk/libc/src/libc/process/system.c
- Timestamp:
- Apr 14, 2014, 4:02:50 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libc/src/libc/process/system.c
r2254 r3857 1 /* system.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */ 1 /* $Id: b_processSetResourceLimit.c 3770 2012-03-15 20:02:46Z bird $ */ 2 /** @file 3 * kNIX - get default shell for system() and popen(). 4 * 5 * @copyright Copyright (C) 2014 knut st. osmundsen <bird-klibc-spam-xiv@anduin.net> 6 * @licenses MIT, BSD2, BSD3, BSD4, LGPLv2.1, LGPLv3. 7 */ 2 8 9 10 /******************************************************************************* 11 * Header Files * 12 *******************************************************************************/ 13 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_PROCESS 3 14 #include "libc-alias.h" 4 15 #include <stdlib.h> 5 #include <string.h> 6 #include <process.h> 16 7 17 #include <io.h> 8 18 #include <errno.h> 9 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_PROCESS 10 #include <InnoTekLIBC/logstrict.h> 19 #include <process.h> 20 #include <unistd.h> 21 #include <klibc/backend.h> 22 #include <klibc/logstrict.h> 11 23 12 int _STD(system)(const char *name) 24 25 int _STD(system)(const char *pszCmdLine) 13 26 { 14 LIBCLOG_ENTER("name=%s\n", name); 15 int rc; 16 const char *sh, *base, *opt; 17 18 sh = getenv("EMXSHELL"); 19 if (sh == NULL) 20 sh = getenv("COMSPEC"); 21 if (sh == NULL) 22 sh = getenv("OS2_SHELL"); 23 if (sh == NULL) 24 sh = getenv("SHELL"); 25 if (sh == NULL) 27 LIBCLOG_ENTER("pszCmdLine=%s\n", pszCmdLine); 28 char szCmdLineOpt[8]; 29 char szShell[260]; 30 size_t offShellArg; 31 int rc = __libc_Back_processGetDefaultShell(szShell, sizeof(szShell), &offShellArg, szCmdLineOpt, sizeof(szCmdLineOpt)); 32 if (rc == 0) 26 33 { 27 errno = ENOENT; 28 LIBCLOG_ERROR_RETURN(-1, "ret -1 - no shell\n"); 34 LIBCLOG_MSG("using shell: %s\n", pszCmdLine); 35 if (pszCmdLine == 0) 36 rc = access(szShell, F_OK) == 0; 37 else if (*pszCmdLine) 38 rc = spawnlp(P_WAIT, szShell, &szShell[offShellArg], (void *)NULL); 39 else 40 rc = spawnlp(P_WAIT, szShell, &szShell[offShellArg], szCmdLineOpt, pszCmdLine, (void *)NULL); 29 41 } 30 LIBCLOG_MSG("using shell: %s\n", sh);31 if (name == NULL) /* Check for command interpreter */32 {33 LIBCLOG_MSG("check shell access\n");34 rc = access(sh, 0) == 0;35 LIBCLOG_RETURN_INT(rc);36 }37 if (*name == 0)38 rc = spawnlp(P_WAIT, sh, sh, (char *)0);39 42 else 40 43 { 41 base = _getname(sh); 42 if ( stricmp(base, "cmd.exe") == 0 43 || stricmp(base, "4os2.exe") == 0 44 || stricmp(base, "command.com") == 0 45 || stricmp(base, "4dos.com") == 0) 46 opt = "/c"; 47 else 48 opt = "-c"; 49 rc = spawnlp(P_WAIT, sh, sh, opt, name, (char *)0); 44 errno = -rc; 45 rc = -1; 50 46 } 51 47 LIBCLOG_RETURN_INT(rc); 52 48 } 49
Note:
See TracChangeset
for help on using the changeset viewer.