Functions makepath() and ifconfig() now provied by libite.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2015-07-10 18:33:47 +02:00
parent 1db144c677
commit b30678bbe9
3 changed files with 2 additions and 68 deletions
+1 -64
View File
@@ -1,4 +1,4 @@
/* Misc. utility functions and C-library extensions for finit and its plugins
/* Misc. utility functions for finit and its plugins
*
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2015 Joachim Nilsson <troglobit@gmail.com>
@@ -40,69 +40,6 @@
#include "libite/lite.h"
/*
* Helpers to replace system() calls
*/
int makepath(char *path)
{
char buf[PATH_MAX];
char *x = buf;
int ret;
if (!path) {
errno = EINVAL;
return -1;
}
do {
do {
*x++ = *path++;
} while (*path && *path != '/');
*x = 0;
ret = mkdir(buf, 0777);
} while (*path && (*path != '/' || *(path + 1))); /* ignore trailing slash */
return ret;
}
void ifconfig(char *ifname, char *addr, char *mask, int up)
{
struct ifreq ifr;
struct sockaddr_in *a = (struct sockaddr_in *)&ifr.ifr_addr;
int sock;
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0)
return;
memset(&ifr, 0, sizeof (ifr));
strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
ifr.ifr_addr.sa_family = AF_INET;
if (up) {
if (addr) {
inet_aton(addr, &a->sin_addr);
ioctl(sock, SIOCSIFADDR, &ifr);
}
if (mask) {
inet_aton(mask, &a->sin_addr);
ioctl(sock, SIOCSIFNETMASK, &ifr);
}
}
ioctl(sock, SIOCGIFFLAGS, &ifr);
if (up)
ifr.ifr_flags |= IFF_UP;
else
ifr.ifr_flags &= ~IFF_UP;
ioctl(sock, SIOCSIFFLAGS, &ifr);
close(sock);
}
/**
* atonum - Convert string to integer
* @str: String value to convert.
-3
View File
@@ -65,9 +65,6 @@ do { \
#define SETBIT(a,i) (a |= (1 << (i)))
#define CLRBIT(a,i) (a &= ~(1 << (i)))
int makepath (char *path);
void ifconfig (char *ifname, char *addr, char *mask, int up);
int atonum (char *str);
void runlevel_set (int pre, int now);
+1 -1
Submodule libite updated: 8db314623a...4005dd5e2c