Skip to content

Commit

Permalink
Merge pull request #410 from okirch/nuke-obsolete-socket-fncts
Browse files Browse the repository at this point in the history
Nuke obsolete socket fncts
  • Loading branch information
wipawel committed Sep 9, 2014
2 parents c372b7d + f26716a commit 3fd3599
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 157 deletions.
5 changes: 0 additions & 5 deletions include/wicked/socket.h
Expand Up @@ -40,11 +40,6 @@ extern const ni_timer_t *ni_timer_rearm(const ni_timer_t *, unsigned long);
extern long ni_timer_next_timeout(void);
extern int ni_timer_get_time(struct timeval *tv);

extern ni_socket_t * ni_local_socket_listen(const char *, unsigned int);
extern ni_socket_t * ni_local_socket_connect(const char *);
extern ni_socket_t * ni_local_socket_accept(ni_socket_t *, uid_t *, gid_t *);
extern int ni_local_socket_pair(ni_socket_t **, ni_socket_t **);

extern ni_socket_t * ni_socket_hold(ni_socket_t *);
extern void ni_socket_release(ni_socket_t *);
extern ni_socket_t * ni_socket_wrap(int fd, int sotype);
Expand Down
1 change: 0 additions & 1 deletion src/appconfig.h
Expand Up @@ -71,7 +71,6 @@ typedef struct ni_config {
ni_config_fslocation_t storedir;
ni_config_fslocation_t statedir;
ni_config_fslocation_t backupdir;
unsigned int recv_max;
ni_bool_t use_nanny;

struct {
Expand Down
2 changes: 0 additions & 2 deletions src/config.c
Expand Up @@ -61,8 +61,6 @@ ni_config_new()
conf->addrconf.dhcp6.allow_update = conf->addrconf.default_allow_update;
conf->addrconf.autoip.allow_update = conf->addrconf.default_allow_update;

conf->recv_max = 64 * 1024;

ni_config_fslocation_init(&conf->piddir, WICKED_PIDDIR, 0755);
ni_config_fslocation_init(&conf->statedir, WICKED_STATEDIR, 0755);
ni_config_fslocation_init(&conf->storedir, WICKED_STOREDIR, 0755);
Expand Down
5 changes: 5 additions & 0 deletions src/process.c
Expand Up @@ -571,6 +571,11 @@ __ni_process_output_recv(ni_socket_t *sock)
int cnt;

ni_assert(pi);

/* Grow socket input buffer as needed.
* NB: we may put an upper limit on how much process output we capture.
* Anything beyond a few MB is insane...
*/
if (ni_buffer_tailroom(rbuf) < 256)
ni_buffer_ensure_tailroom(rbuf, 4096);

Expand Down
149 changes: 0 additions & 149 deletions src/socket.c
Expand Up @@ -31,7 +31,6 @@
#define NI_SOCKET_ARRAY_CHUNK 16

static void __ni_socket_close(ni_socket_t *);
static void __ni_socket_accept(ni_socket_t *);
static void __ni_default_error_handler(ni_socket_t *);
static void __ni_default_hangup_handler(ni_socket_t *);

Expand Down Expand Up @@ -304,154 +303,6 @@ ni_socket_close(ni_socket_t *sock)
ni_socket_release(sock);
}

/*
* Create a listener socket
*/
ni_socket_t *
ni_local_socket_listen(const char *path, unsigned int permissions)
{
ni_socket_t *sock;
int fd, bound = 0;

permissions &= 0777;
fd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (fd < 0) {
ni_error("cannot open AF_LOCAL socket: %m");
return NULL;
}

if (path) {
struct sockaddr_un sun;
unsigned int len = strlen(path);

if (len + 1 > sizeof(sun.sun_path)) {
ni_error("can't set AF_LOCAL address: path too long!");
return NULL;
}

memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_LOCAL;
strcpy(sun.sun_path, path);

unlink(path);
if (bind(fd, (struct sockaddr *) &sun, sizeof(sun)) < 0) {
ni_error("bind(%s) failed: %m", path);
goto failed;
}
bound = 1;

if (chmod(path, permissions) < 0) {
ni_error("chmod(%s, 0%3o) failed: %m", path, permissions);
goto failed;
}

}

if (listen(fd, 128) < 0) {
ni_error("cannot listen on local socket: %m");
goto failed;
}

sock = __ni_socket_wrap(fd, SOCK_STREAM);
sock->receive = __ni_socket_accept;

ni_socket_activate(sock);
return sock;

failed:
if (bound && path)
unlink(path);
close(fd);
return NULL;
}

ni_socket_t *
ni_local_socket_connect(const char *path)
{
int fd;

if (!path) {
ni_error("cannot connect to server - no server socket path specified");
return NULL;
}

fd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (fd < 0) {
ni_error("cannot open AF_LOCAL socket: %m");
return NULL;
}

{
struct sockaddr_un sun;
unsigned int len = strlen(path);

if (len + 1 > sizeof(sun.sun_path)) {
ni_error("can't set AF_LOCAL address: path too long!");
goto failed;
}

memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_LOCAL;
strcpy(sun.sun_path, path);

if (connect(fd, (struct sockaddr *) &sun, sizeof(sun)) < 0) {
ni_error("connect(%s) failed: %m", path);
goto failed;
}
}

return ni_socket_wrap(fd, SOCK_STREAM);

failed:
close(fd);
return NULL;
}

void
__ni_socket_accept(ni_socket_t *master)
{
ni_socket_t *sock;
struct ucred cred;
socklen_t clen;
int fd;

fd = accept(master->__fd, NULL, NULL);
if (fd < 0)
return;

clen = sizeof(cred);
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &clen) < 0) {
ni_error("failed to get client credentials: %m");
close(fd);
return;
}

sock = __ni_socket_wrap(fd, SOCK_STREAM);
if (master->accept == NULL || master->accept(sock, cred.uid, cred.gid) >= 0) {
ni_buffer_init_dynamic(&sock->rbuf, ni_global.config->recv_max);
ni_socket_array_activate(master->active, sock);
}
ni_socket_release(sock);
}

/*
* Create a local socket pair
*/
int
ni_local_socket_pair(ni_socket_t **p1, ni_socket_t **p2)
{
int fd[2];

if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, fd) < 0) {
ni_error("unable to create AF_LOCAL socketpair: %m");
return -1;
}

*p1 = ni_socket_wrap(fd[0], SOCK_DGRAM);
*p2 = ni_socket_wrap(fd[1], SOCK_DGRAM);
return 0;
}

/*
* Socket array manipulation functions
*/
Expand Down

0 comments on commit 3fd3599

Please sign in to comment.