mirror of
https://github.com/troglobit/finit.git
synced 2026-10-08 16:34:45 +07:00
Functions makepath() and ifconfig() now provied by libite.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
Reference in New Issue
Block a user