Plan 9 from Bell Labs’s /usr/web/sources/patch/applied/schtarb-2nd/system.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include "lib.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>

int
system(const char *s)
{
	int w, status;
	pid_t pid;
	char cmd[30], *oty;

	oty = getenv("objtype");
	if(!oty)
		return -1;
	if(!s)
		return 1; /* a command interpreter is available */
	pid = fork();
	snprintf(cmd, sizeof(cmd), "/%s/bin/ape/sh", oty);
	if(pid == 0) {
		execl(cmd, "sh", "-c", s, 0);
		_exit(1);
	}
	if(pid < 0){
		_syserrno();
		return -1;
	}
	for(;;) {
		w = wait(&status);
		if(w == -1 || w == pid)
			break;
	}

	if(w == -1){
		_syserrno();
		return w;
	}
	return status;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].