mirror of
https://github.com/pygos/init.git
synced 2024-11-05 12:17:10 +01:00
34 lines
516 B
C
34 lines
516 B
C
|
#include <sys/types.h>
|
||
|
#include <sys/socket.h>
|
||
|
#include <sys/un.h>
|
||
|
#include <unistd.h>
|
||
|
#include <string.h>
|
||
|
#include <stdio.h>
|
||
|
|
||
|
#include "telinit.h"
|
||
|
|
||
|
int opensock(void)
|
||
|
{
|
||
|
struct sockaddr_un un;
|
||
|
int fd;
|
||
|
|
||
|
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||
|
if (fd < 0) {
|
||
|
perror("socket");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
memset(&un, 0, sizeof(un));
|
||
|
un.sun_family = AF_UNIX;
|
||
|
|
||
|
strcpy(un.sun_path, INITSOCK);
|
||
|
|
||
|
if (connect(fd, (struct sockaddr *)&un, sizeof(un))) {
|
||
|
perror("connect: " INITSOCK);
|
||
|
close(fd);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
return fd;
|
||
|
}
|