mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-21 13:28:05 +01:00
Half-assed fix to make autoconf bend
- this should make platform detection automagic - also fixes debian builds that broke in the meantime - fix osdep_darwin.c
This commit is contained in:
committed by
Carlos R. Mafra
parent
67a8a82670
commit
55959b4f7e
80
src/osdep_linux.c
Normal file
80
src/osdep_linux.c
Normal file
@@ -0,0 +1,80 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <WINGs/WUtil.h>
|
||||
|
||||
#include "wconfig.h"
|
||||
|
||||
/*
|
||||
* copy argc and argv for an existing process identified by `pid'
|
||||
* into suitable storage given in ***argv and *argc.
|
||||
*
|
||||
* subsequent calls use the same static area for argv and argc.
|
||||
*
|
||||
* returns 0 for failure, in which case argc := 0 and argv := NULL
|
||||
* returns 1 for success
|
||||
*/
|
||||
Bool GetCommandForPid(int pid, char ***argv, int *argc)
|
||||
{
|
||||
static char buf[_POSIX_ARG_MAX];
|
||||
int fd, i, j;
|
||||
ssize_t count;
|
||||
|
||||
*argv = NULL;
|
||||
*argc = 0;
|
||||
|
||||
/* cmdline is a flattened series of null-terminated strings */
|
||||
snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
|
||||
while (1) {
|
||||
if ((fd = open(buf, O_RDONLY)) != -1)
|
||||
break;
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
return False;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if ((count = read(fd, buf, sizeof(buf))) != -1)
|
||||
break;
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
return False;
|
||||
}
|
||||
|
||||
do {
|
||||
close(fd);
|
||||
} while (errno == EINTR);
|
||||
|
||||
/* count args */
|
||||
for (i = 0; i < count; i++)
|
||||
if (buf[i] == '\0')
|
||||
(*argc)++;
|
||||
|
||||
if (*argc == 0)
|
||||
return False;
|
||||
|
||||
*argv = (char **)wmalloc(sizeof(char *) * (*argc + 1 /* term. null ptr */));
|
||||
(*argv)[0] = buf;
|
||||
|
||||
/* go through buf, set argv[$next] to the beginning of each string */
|
||||
for (i = 0, j = 1; i < count; i++) {
|
||||
if (buf[i] != '\0')
|
||||
continue;
|
||||
if (i < count - 1)
|
||||
(*argv)[j++] = &buf[i + 1];
|
||||
if (j == *argc)
|
||||
break;
|
||||
}
|
||||
|
||||
/* the list of arguments must be terminated by a null pointer */
|
||||
(*argv)[j] = NULL;
|
||||
return True;
|
||||
}
|
||||
Reference in New Issue
Block a user