simplify getconf and confstr stuff

This commit is contained in:
tg 2006-11-09 22:08:08 +00:00
parent bc215df211
commit d4ca2c9141
3 changed files with 21 additions and 20 deletions

10
jobs.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.11 2006/08/28 01:25:33 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.12 2006/11/09 22:08:07 tg Exp $");
/* Order important! */
#define PRUNNING 0
@ -92,8 +92,10 @@ static pid_t async_pid;
static int nzombie; /* # of zombies owned by this process */
static int32_t njobs; /* # of jobs started */
static int child_max; /* CHILD_MAX */
#ifndef CHILD_MAX
#define CHILD_MAX _POSIX_CHILD_MAX
#endif
/* held_sigchld is set if sigchld occurs before a job is completely started */
static volatile sig_atomic_t held_sigchld;
@ -121,8 +123,6 @@ static int kill_job(Job *, int);
void
j_init(int mflagset)
{
child_max = sysconf(_SC_CHILD_MAX);
sigemptyset(&sm_default);
sigprocmask(SIG_SETMASK, &sm_default, NULL);
@ -840,7 +840,7 @@ j_set_async(Job *j)
}
async_job = j;
async_pid = j->last_proc->pid;
while (nzombie > child_max) {
while (nzombie > CHILD_MAX) {
oldest = NULL;
for (jl = job_list; jl; jl = jl->next)
if (jl != async_job && (jl->flags & JF_ZOMBIE) &&

24
main.c
View File

@ -13,7 +13,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.51 2006/11/08 23:45:47 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.52 2006/11/09 22:08:07 tg Exp $");
extern char **environ;
@ -67,6 +67,10 @@ main(int argc, char *argv[])
pid_t ppid;
struct tbl *vp;
struct stat s_stdin;
#if !defined(_PATH_DEFPATH) && defined(_CS_PATH)
size_t k;
char *cp;
#endif
#if HAVE_SETLOCALE_CTYPE
const char *cc;
#endif
@ -123,17 +127,17 @@ main(int argc, char *argv[])
init_histvec();
#ifdef _PATH_DEFPATH
def_path = _PATH_DEFPATH;
#else
#ifdef _CS_PATH
{
size_t len;
char *new;
if ((len = confstr(_CS_PATH, NULL, 0)) > 0) {
confstr(_CS_PATH, new = alloc(len + 1, APERM), len + 1);
def_path = new;
}
}
if ((len = confstr(_CS_PATH, NULL, 0)) != (size_t)-1 &&
len > 0 && confstr(_CS_PATH, new = alloc(len + 1, APERM),
len + 1) == len + 1)
def_path = new;
else
#endif
def_path = "/bin:/usr/bin:/sbin:/usr/sbin";
#endif
/* Set PATH to def_path (will set the path global variable).

7
sh.h
View File

@ -8,7 +8,7 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.62 2006/11/09 21:20:49 tg Exp $"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.63 2006/11/09 22:08:08 tg Exp $"
#define MKSH_VERSION "R29 2006/11/09"
#if HAVE_SYS_PARAM_H
@ -158,10 +158,7 @@ typedef int32_t Tflag;
#define LINE 4096 /* input line size */
#ifndef PATH_MAX
#define PATH_MAX 1024 /* pathname size (todo: PATH_MAX/pathconf()) */
#endif
#ifndef _PATH_DEFPATH
#define _PATH_DEFPATH "/bin:/usr/bin:/sbin:/usr/sbin"
#define PATH_MAX 1024 /* pathname size */
#endif
EXTERN char *kshname; /* $0 */