File: ssid.c

package info (click to toggle)
suckless-tools 47-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 768 kB
  • sloc: ansic: 3,434; makefile: 448; sh: 80
file content (39 lines) | stat: -rw-r--r-- 741 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

int
main(int argc, char *argv[]) {
	if(argc < 2) {
		fputs("usage: ssid [-v] cmd [arg ...]\n", stderr);
		exit(EXIT_FAILURE);
	}
	else if(!strncmp(argv[1], "-v", 3)) {
		fputs("ssid-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
		exit(EXIT_SUCCESS);
	}
	if(getpgrp() == getpid()) {
		switch(fork()){
			case -1:
				perror("ssid: fork");
				exit(1);
			case 0:
				break;
			default:
				exit(0);
		}
	}
	if(setsid() < 0) {
		perror("ssid: setsid");
		exit(1);
	}
	execvp(argv[1], argv + 1);
	perror("ssid: execvp");
	exit(1);
	return 0;
}