f93cf255d4
Closes #238 Update all files to list SPDX license shortname. Most files are BSD 3 clause license. The exceptions are: serge@sl ~/src/shadow$ git grep SPDX-License | grep -v BSD-3-Clause contrib/atudel:# SPDX-License-Identifier: BSD-4-Clause lib/tcbfuncs.c: * SPDX-License-Identifier: 0BSD libmisc/salt.c: * SPDX-License-Identifier: Unlicense src/login_nopam.c: * SPDX-License-Identifier: Unlicense src/nologin.c: * SPDX-License-Identifier: BSD-2-Clause src/vipw.c: * SPDX-License-Identifier: GPL-2.0-or-later Signed-off-by: Serge Hallyn <serge@hallyn.com>
62 lines
1.3 KiB
C
62 lines
1.3 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2011 , Jonathan Nieder
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include "exitcodes.h"
|
|
#include "prototypes.h"
|
|
|
|
int run_command (const char *cmd, const char *argv[],
|
|
/*@null@*/const char *envp[], /*@out@*/int *status)
|
|
{
|
|
pid_t pid, wpid;
|
|
|
|
if (NULL == envp) {
|
|
envp = (const char **)environ;
|
|
}
|
|
|
|
(void) fflush (stdout);
|
|
(void) fflush (shadow_logfd);
|
|
|
|
pid = fork ();
|
|
if (0 == pid) {
|
|
(void) execve (cmd, (char * const *) argv,
|
|
(char * const *) envp);
|
|
if (ENOENT == errno) {
|
|
exit (E_CMD_NOTFOUND);
|
|
}
|
|
fprintf (shadow_logfd, "%s: cannot execute %s: %s\n",
|
|
Prog, cmd, strerror (errno));
|
|
exit (E_CMD_NOEXEC);
|
|
} else if ((pid_t)-1 == pid) {
|
|
fprintf (shadow_logfd, "%s: cannot execute %s: %s\n",
|
|
Prog, cmd, strerror (errno));
|
|
return -1;
|
|
}
|
|
|
|
do {
|
|
wpid = waitpid (pid, status, 0);
|
|
if ((pid_t)-1 == wpid && errno == ECHILD)
|
|
break;
|
|
} while ( ((pid_t)-1 == wpid && errno == EINTR)
|
|
|| ((pid_t)-1 != wpid && wpid != pid));
|
|
|
|
if ((pid_t)-1 == wpid) {
|
|
fprintf (shadow_logfd, "%s: waitpid (status: %d): %s\n",
|
|
Prog, *status, strerror (errno));
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|