No way. As I said before, this breaks git blame history. We decided not to do this before and the arguments against it are still valid. ----- "Peter Jones" <pjones@xxxxxxxxxx> wrote: > If we're saying to use a particular coding style, we should at least > try to do something close to it everywhere. > --- > isys/auditd.c | 142 +- > isys/cpio.c | 39 +- > isys/cpio.h | 37 +- > isys/dasd.c | 245 ++-- > isys/devices.c | 352 +++-- > isys/devices.h | 22 +- > isys/eddsupport.c | 451 +++--- > isys/eddsupport.h | 4 +- > isys/ethtool.c | 151 +- > isys/ethtool.h | 18 +- > isys/iface.c | 744 +++++----- > isys/iface.h | 113 +- > isys/imount.c | 475 +++--- > isys/imount.h | 2 +- > isys/isofs.c | 55 +- > isys/isys.c | 1055 +++++++------ > isys/isys.h | 8 +- > isys/lang.c | 270 ++-- > isys/lang.h | 14 +- > isys/linkdetect.c | 203 ++-- > isys/minifind.c | 73 +- > isys/minifind.h | 14 +- > isys/str.c | 91 +- > isys/uncpio.c | 1282 ++++++++------- > isys/vio.c | 127 +- > loader/cdinstall.c | 851 ++++++----- > loader/cdinstall.h | 9 +- > loader/copy.c | 228 ++-- > loader/copy.h | 4 +- > loader/devices.h | 120 +- > loader/dirbrowser.c | 271 ++-- > loader/dirbrowser.h | 4 +- > loader/driverdisk.c | 1112 +++++++------- > loader/driverdisk.h | 9 +- > loader/driverselect.c | 419 +++--- > loader/fwloader.c | 1013 ++++++------ > loader/getparts.c | 265 ++-- > loader/getparts.h | 2 +- > loader/hardware.c | 273 ++-- > loader/hdinstall.c | 819 +++++----- > loader/hdinstall.h | 12 +- > loader/ibft.c | 45 +- > loader/ibft.h | 17 +- > loader/init.c | 1423 +++++++++-------- > loader/kbd.c | 207 ++-- > loader/kbd.h | 6 +- > loader/kickstart.c | 868 ++++++----- > loader/kickstart.h | 8 +- > loader/lang.c | 631 ++++---- > loader/lang.h | 15 +- > loader/loader.c | 4072 > +++++++++++++++++++++++++----------------------- > loader/loader.h | 84 +- > loader/loadermisc.c | 201 ++-- > loader/loadermisc.h | 8 +- > loader/log.c | 177 ++- > loader/log.h | 8 +- > loader/mediacheck.c | 148 +- > loader/method.c | 813 +++++----- > loader/method.h | 37 +- > loader/mkctype.c | 71 +- > loader/moduleinfo.c | 469 +++--- > loader/moduleinfo.h | 52 +- > loader/modules.c | 677 ++++---- > loader/modules.h | 4 +- > loader/net.c | 3861 > ++++++++++++++++++++++++---------------------- > loader/net.h | 43 +- > loader/nfsinstall.c | 1043 +++++++------ > loader/nfsinstall.h | 20 +- > loader/selinux.c | 29 +- > loader/shutdown.c | 98 +- > loader/telnet.c | 344 +++-- > loader/telnet.h | 10 +- > loader/telnetd.c | 333 ++-- > loader/telnetd.h | 2 +- > loader/udelay.h | 203 ++-- > loader/undomounts.c | 368 +++-- > loader/urlinstall.c | 700 +++++---- > loader/urlinstall.h | 12 +- > loader/urls.c | 626 ++++---- > loader/urls.h | 8 +- > loader/windows.c | 134 +- > loader/windows.h | 11 +- > mini-wm.c | 135 +- > utils/geninitrdsz.c | 46 +- > utils/mapshdr.c | 58 +- > utils/mk-s390-cdboot.c | 546 ++++--- > utils/modlist.c | 232 ++-- > utils/readmap.c | 152 +- > utils/snarffont.c | 113 +- > xutils.c | 393 +++--- > 90 files changed, 16064 insertions(+), 14895 deletions(-) > > diff --git a/isys/auditd.c b/isys/auditd.c > index f050550..ee90122 100644 > --- a/isys/auditd.c > +++ b/isys/auditd.c > @@ -40,93 +40,95 @@ static int done; > > static void sig_done(int sig) > { > - done = 1; > + done = 1; > } > > -static void do_auditd(int fd) { > - struct audit_reply rep; > - sigset_t sigs; > - struct sigaction sa; > - struct pollfd pds = { > - .events = POLLIN, > - .revents = 0, > - .fd = fd, > - }; > - > - if (audit_set_pid(fd, getpid(), WAIT_YES) < 0) > - return; > - > - if (audit_set_enabled(fd, 1) < 0) > - return; > - > - memset(&sa, '\0', sizeof (sa)); > - sa.sa_handler = sig_done; > - sigaction(SIGTERM, &sa, NULL); > - sigaction(SIGINT, &sa, NULL); > - sigaction(SIGHUP, &sa, NULL); > - > - sigfillset(&sigs); > - sigdelset(&sigs, SIGTERM); > - sigdelset(&sigs, SIGINT); > - sigdelset(&sigs, SIGHUP); > - > - while (1) { > - int retval; > - > - memset(&rep, 0, sizeof(rep)); > - > - do { > - retval = ppoll(&pds, 1, NULL, &sigs); > - } while (retval == -1 && errno == EINTR && !done); > - > - if (done) > - break; > - > - if (audit_get_reply(fd, &rep, GET_REPLY_NONBLOCKING, 0) > 0) > { > - /* we don't actually want to do anything here. */ > - ; > - } > - } > - return; > +static void do_auditd(int fd) > +{ > + struct audit_reply rep; > + sigset_t sigs; > + struct sigaction sa; > + struct pollfd pds = { > + .events = POLLIN, > + .revents = 0, > + .fd = fd, > + }; > + > + if (audit_set_pid(fd, getpid(), WAIT_YES) < 0) > + return; > + > + if (audit_set_enabled(fd, 1) < 0) > + return; > + > + memset(&sa, '\0', sizeof(sa)); > + sa.sa_handler = sig_done; > + sigaction(SIGTERM, &sa, NULL); > + sigaction(SIGINT, &sa, NULL); > + sigaction(SIGHUP, &sa, NULL); > + > + sigfillset(&sigs); > + sigdelset(&sigs, SIGTERM); > + sigdelset(&sigs, SIGINT); > + sigdelset(&sigs, SIGHUP); > + > + while (1) { > + int retval; > + > + memset(&rep, 0, sizeof(rep)); > + > + do { > + retval = ppoll(&pds, 1, NULL, &sigs); > + } while (retval == -1 && errno == EINTR && !done); > + > + if (done) > + break; > + > + if (audit_get_reply(fd, &rep, GET_REPLY_NONBLOCKING, 0) > 0) { > + /* we don't actually want to do anything here. */ > + ; > + } > + } > + return; > } > #endif /* USESELINUX */ > > -int audit_daemonize(void) { > +int audit_daemonize(void) > +{ > #ifdef USESELINUX > - int fd; > -#ifndef STANDALONE > - int i; > - pid_t child; > - > - if ((child = fork()) > 0) > - return 0; > + int fd; > +#ifndef STANDALONE > + int i; > + pid_t child; > > - for (i = 0; i < getdtablesize(); i++) > - close(i); > + if ((child = fork()) > 0) > + return 0; > > - signal(SIGTTOU, SIG_IGN); > - signal(SIGTTIN, SIG_IGN); > - signal(SIGTSTP, SIG_IGN); > + for (i = 0; i < getdtablesize(); i++) > + close(i); > > - if ((fd = open("/proc/self/oom_adj", O_RDWR)) >= 0) { > - i = write(fd, "-17", 3); > - close(fd); > - } > + signal(SIGTTOU, SIG_IGN); > + signal(SIGTTIN, SIG_IGN); > + signal(SIGTSTP, SIG_IGN); > > + if ((fd = open("/proc/self/oom_adj", O_RDWR)) >= 0) { > + i = write(fd, "-17", 3); > + close(fd); > + } > #endif /* !defined(STANDALONE) */ > - fd = audit_open(); > - do_auditd(fd); > - audit_close(fd); > + fd = audit_open(); > + do_auditd(fd); > + audit_close(fd); > #ifndef STANDALONE > - exit(0); > + exit(0); > #endif /* !defined(STANDALONE) */ > #endif /* USESELINUX */ > - return 0; > + return 0; > } > > #ifdef STANDALONE > -int main(void) { > - return audit_daemonize(); > +int main(void) > +{ > + return audit_daemonize(); > } > #endif /* STANDALONE */ > > diff --git a/isys/cpio.c b/isys/cpio.c > index bebc795..acb613f 100644 > --- a/isys/cpio.c > +++ b/isys/cpio.c > @@ -24,25 +24,26 @@ > > #include "cpio.h" > > -int installCpioFile(gzFile fd, char * cpioName, char * outName, int > inWin) { > - struct cpioFileMapping map; > - int rc; > - const char * failedFile; > - > - if (outName) { > - map.archivePath = cpioName; > - map.fsPath = outName; > - map.mapFlags = CPIO_MAP_PATH; > - } > - > - rc = myCpioInstallArchive(fd, outName ? &map : NULL, 1, NULL, > NULL, > - &failedFile); > - > - if (rc || access(outName, R_OK)) { > - return -1; > - } > - > - return 0; > +int installCpioFile(gzFile fd, char *cpioName, char *outName, int > inWin) > +{ > + struct cpioFileMapping map; > + int rc; > + const char *failedFile; > + > + if (outName) { > + map.archivePath = cpioName; > + map.fsPath = outName; > + map.mapFlags = CPIO_MAP_PATH; > + } > + > + rc = myCpioInstallArchive(fd, outName ? &map : NULL, 1, NULL, NULL, > + &failedFile); > + > + if (rc || access(outName, R_OK)) { > + return -1; > + } > + > + return 0; > } > > /* vim:set sw=8 noet */ > diff --git a/isys/cpio.h b/isys/cpio.h > index 6f76a6d..573f65b 100644 > --- a/isys/cpio.h > +++ b/isys/cpio.h > @@ -50,7 +50,6 @@ > #define CPIOERR_HDR_SIZE (21 ) > #define CPIOERR_UNKNOWN_FILETYPE (22 ) > > - > /* Don't think this behaves just like standard cpio. It's pretty > close, but > it has some behaviors which are more to RPM's liking. I tried to > document > them inline in cpio.c, but I may have missed some. */ > @@ -59,26 +58,26 @@ > #define CPIO_MAP_MODE (1 << 1) > #define CPIO_MAP_UID (1 << 2) > #define CPIO_MAP_GID (1 << 3) > -#define CPIO_FOLLOW_SYMLINKS (1 << 4) /* only for building */ > +#define CPIO_FOLLOW_SYMLINKS (1 << 4) /* only for building */ > > struct cpioFileMapping { > - char * archivePath; > - char * fsPath; > - mode_t finalMode; > - uid_t finalUid; > - gid_t finalGid; > - int mapFlags; > + char *archivePath; > + char *fsPath; > + mode_t finalMode; > + uid_t finalUid; > + gid_t finalGid; > + int mapFlags; > }; > > /* on cpio building, only "file" is filled in */ > struct cpioCallbackInfo { > - char * file; > - long fileSize; /* total file size */ > - long fileComplete; /* amount of file unpacked */ > - long bytesProcessed; /* bytes in archive read */ > + char *file; > + long fileSize; /* total file size */ > + long fileComplete; /* amount of file unpacked */ > + long bytesProcessed; /* bytes in archive read */ > }; > > -typedef void (*cpioCallback)(struct cpioCallbackInfo * filespec, void > * data); > +typedef void (*cpioCallback) (struct cpioCallbackInfo * filespec, > void *data); > > /* If no mappings are passed, this installs everything! If one is > passed > it should be sorted according to cpioFileMapCmp() and only files > included > @@ -87,17 +86,17 @@ typedef void (*cpioCallback)(struct > cpioCallbackInfo * filespec, void * data); > directory. The mode mapping is only used for the permission bits, > not > for the file type. The owner/group mappings are ignored for the > nonroot > user. If *failedFile is non-NULL on return, it should be free()d. > */ > -int myCpioInstallArchive(gzFile stream, struct cpioFileMapping * > mappings, > - int numMappings, cpioCallback cb, void * cbData, > - const char ** failedFile); > -int myCpioFilterArchive(gzFile inStream, gzFile outStream, char ** > pattern); > +int myCpioInstallArchive(gzFile stream, struct cpioFileMapping > *mappings, > + int numMappings, cpioCallback cb, void *cbData, > + const char **failedFile); > +int myCpioFilterArchive(gzFile inStream, gzFile outStream, char > **pattern); > > /* This is designed to be qsort/bsearch compatible */ > -int myCpioFileMapCmp(const void * a, const void * b); > +int myCpioFileMapCmp(const void *a, const void *b); > > const char *myCpioStrerror(int rc); > > -int installCpioFile(gzFile fd, char * cpioName, char * outName, int > inWin); > +int installCpioFile(gzFile fd, char *cpioName, char *outName, int > inWin); > > #endif > > diff --git a/isys/dasd.c b/isys/dasd.c > index 3b07f25..17f4783 100644 > --- a/isys/dasd.c > +++ b/isys/dasd.c > @@ -41,139 +41,150 @@ > > #if defined(__s390__) || defined(__s390x__) > /* s390 stuff to detect DASDs */ > -static int read_vlabel(dasd_information_t *dasd_info, int fd, int > blksize, > - volume_label_t *vlabel) { > - int rc; > - unsigned long vlabel_start = dasd_info->label_block * blksize; > +static int read_vlabel(dasd_information_t * dasd_info, int fd, int > blksize, > + volume_label_t * vlabel) > +{ > + int rc; > + unsigned long vlabel_start = dasd_info->label_block * blksize; > > - memset(vlabel, 0, sizeof(volume_label_t)); > + memset(vlabel, 0, sizeof(volume_label_t)); > > - if (lseek(fd, vlabel_start, SEEK_SET) < 0) { > - return 2; > - } > + if (lseek(fd, vlabel_start, SEEK_SET) < 0) { > + return 2; > + } > > - rc = read(fd, vlabel, sizeof(volume_label_t)); > - if (rc != sizeof(volume_label_t)) { > - return 1; > - } > + rc = read(fd, vlabel, sizeof(volume_label_t)); > + if (rc != sizeof(volume_label_t)) { > + return 1; > + } > > - return 0; > + return 0; > } > #endif > > -int isUsableDasd(char *device) { > +int isUsableDasd(char *device) > +{ > #if !defined(__s390__) && !defined(__s390x__) > - return 0; > + return 0; > #else > - char devname[16]; > - char label[5], v4_hex[9]; > - char l4ebcdic_hex[] = "d3d5e7f1"; /* LNX1 */ > - char cms1_hex[] = "c3d4e2f1"; /* CMS1 */ > - int f, ret, blksize; > - dasd_information_t dasd_info; > - volume_label_t vlabel; > - > - memset(&dasd_info, 0, sizeof(dasd_info)); > - strcpy(devname, "/dev/"); > - strcat(devname, device); > - > - if ((f = open(devname, O_RDONLY)) == -1) > - return 0; > - > - if (ioctl(f, BLKSSZGET, &blksize) != 0) { > - close(f); > - return 0; > - } > - > - if (ioctl(f, BIODASDINFO, &dasd_info) != 0) { > - close(f); > - return 0; > - } > - > - ret = read_vlabel(&dasd_info, f, blksize, &vlabel); > - close(f); > - > - if (ret == 2) > - return 0; > - else if (ret == 1) /* probably unformatted DASD */ > - return 1; > - > - memset(label, 0, 5); > - memset(v4_hex, 0, 9); > - strncpy(label, vlabel.volkey, 4); > - > - ret = sprintf(v4_hex, "%02x%02x%02x%02x", label[0], label[1], > - label[2], label[3]); > - if (ret < 0 || ret < strlen(cms1_hex)) > - return 3; > - > - if (!strncmp(v4_hex, cms1_hex, 9)) > - return 0; > - > - if (!strncmp(v4_hex, l4ebcdic_hex, 9)) > - return 2; > - > - return 1; > + char devname[16]; > + char label[5], v4_hex[9]; > + char l4ebcdic_hex[] = "d3d5e7f1"; /* LNX1 */ > + char cms1_hex[] = "c3d4e2f1"; /* CMS1 */ > + int f, ret, blksize; > + dasd_information_t dasd_info; > + volume_label_t vlabel; > + > + memset(&dasd_info, 0, sizeof(dasd_info)); > + strcpy(devname, "/dev/"); > + strcat(devname, device); > + > + if ((f = open(devname, O_RDONLY)) == -1) > + return 0; > + > + if (ioctl(f, BLKSSZGET, &blksize) != 0) { > + close(f); > + return 0; > + } > + > + if (ioctl(f, BIODASDINFO, &dasd_info) != 0) { > + close(f); > + return 0; > + } > + > + ret = read_vlabel(&dasd_info, f, blksize, &vlabel); > + close(f); > + > + if (ret == 2) > + return 0; > + else if (ret == 1) /* probably unformatted DASD */ > + return 1; > + > + memset(label, 0, 5); > + memset(v4_hex, 0, 9); > + strncpy(label, vlabel.volkey, 4); > + > + ret = sprintf(v4_hex, "%02x%02x%02x%02x", label[0], label[1], > + label[2], label[3]); > + if (ret < 0 || ret < strlen(cms1_hex)) > + return 3; > + > + if (!strncmp(v4_hex, cms1_hex, 9)) > + return 0; > + > + if (!strncmp(v4_hex, l4ebcdic_hex, 9)) > + return 2; > + > + return 1; > #endif > } > > -int isLdlDasd(char * device) { > - return (isUsableDasd(device) == 2); > +int isLdlDasd(char *device) > +{ > + return (isUsableDasd(device) == 2); > } > > -char *getDasdPorts() { > +char *getDasdPorts() > +{ > #if !defined(__s390__) && !defined(__s390x__) > - return 0; > + return 0; > #else > - char * line, *ports = NULL; > - char devname[7]; > - char port[10]; > - FILE *fd; > - int ret, sz; > - > - fd = fopen("/proc/dasd/devices", "r"); > - if (!fd) > - return NULL; > - > - if ((line = (char *)malloc(100 * sizeof(char))) == NULL) { > - fclose(fd); > - return NULL; > - } > - > - while (fgets(line, 100, fd) != NULL) { > - if ((strstr(line, "unknown") != NULL)) > - continue; > - > - if (strstr(line, "(FBA )") != NULL) > - ret = sscanf(line, "%[A-Za-z.0-9](FBA ) at ( %*d: %*d) is > %s : %*s", port, devname); > - else > - ret = sscanf(line, "%[A-Za-z.0-9](ECKD) at ( %*d: %*d) is > %s : %*s", port, devname); > - > - if (ret == 2) { > - if (!ports) { > - sz = strlen(port) + 1; > - if ((ports = (char *) malloc(sz)) == NULL) { > - fclose(fd); > - return NULL; > - } > - > - ports = strcpy(ports, port); > - } else { > - sz = strlen(ports) + strlen(port) + 2; > - if ((ports = (char *) realloc(ports, sz)) == NULL) { > - fclose(fd); > - return NULL; > - } > - > - ports = strcat(ports, ","); > - ports = strcat(ports, port); > - } > - } > - } > - > - fclose(fd); > - > - return ports; > + char *line, *ports = NULL; > + char devname[7]; > + char port[10]; > + FILE *fd; > + int ret, sz; > + > + fd = fopen("/proc/dasd/devices", "r"); > + if (!fd) > + return NULL; > + > + if ((line = (char *)malloc(100 * sizeof(char))) == NULL) { > + fclose(fd); > + return NULL; > + } > + > + while (fgets(line, 100, fd) != NULL) { > + if ((strstr(line, "unknown") != NULL)) > + continue; > + > + if (strstr(line, "(FBA )") != NULL) > + ret = > + sscanf(line, > + "%[A-Za-z.0-9](FBA ) at ( %*d: %*d) is %s : %*s", > + port, devname); > + else > + ret = > + sscanf(line, > + "%[A-Za-z.0-9](ECKD) at ( %*d: %*d) is %s : %*s", > + port, devname); > + > + if (ret == 2) { > + if (!ports) { > + sz = strlen(port) + 1; > + if ((ports = (char *)malloc(sz)) == NULL) { > + fclose(fd); > + return NULL; > + } > + > + ports = strcpy(ports, port); > + } else { > + sz = strlen(ports) + strlen(port) + 2; > + if ((ports = > + (char *)realloc(ports, sz)) == NULL) { > + fclose(fd); > + return NULL; > + } > + > + ports = strcat(ports, ","); > + ports = strcat(ports, port); > + } > + } > + } > + > + fclose(fd); > + > + return ports; > #endif > } > > diff --git a/isys/devices.c b/isys/devices.c > index ef4384d..56f562b 100644 > --- a/isys/devices.c > +++ b/isys/devices.c > @@ -34,7 +34,7 @@ > #include "devices.h" > > /* for 'disks', to filter out weird stuff */ > -#define MINIMUM_INTERESTING_SIZE 32*1024 /* 32MB */ > +#define MINIMUM_INTERESTING_SIZE 32*1024 /* 32MB */ > > /* from genhd.h, kernel side */ > #define GENHD_FL_REMOVABLE 1 > @@ -45,175 +45,193 @@ > #define GENHD_FL_SUPPRESS_PARTITION_INFO 32 > #define GENHD_FL_FAIL 64 > > - > -struct device **getDevices(enum deviceType type) { > - struct device **ret = NULL; > - struct device *new; > - int numdevices = 0; > - > - if (type & (DEVICE_DISK | DEVICE_CDROM)) { > - DIR *dir; > - struct dirent *ent; > - > - dir = opendir("/sys/block"); > - > - if (!dir) goto storagedone; > - > - while ((ent = readdir(dir))) { > - char path[64]; > - char buf[64]; > - int fd, caps, devtype; > - > - snprintf(path, 64, "/sys/block/%s/capability", > ent->d_name); > - fd = open(path, O_RDONLY); > - if (fd == -1) > - continue; > - if (read(fd, buf, 63) <= 0) { > - close(fd); > - continue; > - } > - > - close(fd); > - errno = 0; > - caps = strtol(buf, NULL, 16); > - > - if ((errno == ERANGE && (caps == LONG_MIN || caps == > LONG_MAX)) || > - (errno != 0 && caps == 0)) { > - return NULL; > - } > - > - if (caps & GENHD_FL_CD) > - devtype = DEVICE_CDROM; > - else > - devtype = DEVICE_DISK; > - if (!(devtype & type)) > - continue; > - > - if (devtype == DEVICE_DISK && !(caps & > GENHD_FL_REMOVABLE)) { > - int size; > - > - snprintf(path, 64, "/sys/block/%s/size", > ent->d_name); > - fd = open(path, O_RDONLY); > - > - if (fd == -1) > - continue; > - if (read(fd, buf, 63) <= 0) { > - close(fd); > - continue; > - } > - > - close(fd); > - errno = 0; > - size = strtol(buf, NULL, 10); > - > - if ((errno == ERANGE && (size == LONG_MIN || > - size == LONG_MAX)) || > - (errno != 0 && size == 0)) { > - return NULL; > - } > - > - if (size < MINIMUM_INTERESTING_SIZE) > - continue; > - } > - > - new = calloc(1, sizeof(struct device)); > - new->device = strdup(ent->d_name); > - /* FIXME */ > - if (asprintf(&new->description, "Storage device %s", > - new->device) == -1) { > - fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__, > - strerror(errno)); > - fflush(stderr); > - abort(); > - } > - new->type = devtype; > - if (caps & GENHD_FL_REMOVABLE) { > - new->priv.removable = 1; > - } > - ret = realloc(ret, (numdevices+2) * sizeof(struct > device)); > - ret[numdevices] = new; > - ret[numdevices+1] = NULL; > - numdevices++; > - } > - } > +struct device **getDevices(enum deviceType type) > +{ > + struct device **ret = NULL; > + struct device *new; > + int numdevices = 0; > + > + if (type & (DEVICE_DISK | DEVICE_CDROM)) { > + DIR *dir; > + struct dirent *ent; > + > + dir = opendir("/sys/block"); > + > + if (!dir) > + goto storagedone; > + > + while ((ent = readdir(dir))) { > + char path[64]; > + char buf[64]; > + int fd, caps, devtype; > + > + snprintf(path, 64, "/sys/block/%s/capability", > + ent->d_name); > + fd = open(path, O_RDONLY); > + if (fd == -1) > + continue; > + if (read(fd, buf, 63) <= 0) { > + close(fd); > + continue; > + } > + > + close(fd); > + errno = 0; > + caps = strtol(buf, NULL, 16); > + > + if ((errno == ERANGE > + && (caps == LONG_MIN || caps == LONG_MAX)) > + || (errno != 0 && caps == 0)) { > + return NULL; > + } > + > + if (caps & GENHD_FL_CD) > + devtype = DEVICE_CDROM; > + else > + devtype = DEVICE_DISK; > + if (!(devtype & type)) > + continue; > + > + if (devtype == DEVICE_DISK > + && !(caps & GENHD_FL_REMOVABLE)) { > + int size; > + > + snprintf(path, 64, "/sys/block/%s/size", > + ent->d_name); > + fd = open(path, O_RDONLY); > + > + if (fd == -1) > + continue; > + if (read(fd, buf, 63) <= 0) { > + close(fd); > + continue; > + } > + > + close(fd); > + errno = 0; > + size = strtol(buf, NULL, 10); > + > + if ((errno == ERANGE && (size == LONG_MIN || > + size == LONG_MAX)) || > + (errno != 0 && size == 0)) { > + return NULL; > + } > + > + if (size < MINIMUM_INTERESTING_SIZE) > + continue; > + } > + > + new = calloc(1, sizeof(struct device)); > + new->device = strdup(ent->d_name); > + /* FIXME */ > + if (asprintf(&new->description, "Storage device %s", > + new->device) == -1) { > + fprintf(stderr, "%s: %d: %s\n", __func__, > + __LINE__, strerror(errno)); > + fflush(stderr); > + abort(); > + } > + new->type = devtype; > + if (caps & GENHD_FL_REMOVABLE) { > + new->priv.removable = 1; > + } > + ret = > + realloc(ret, > + (numdevices + 2) * sizeof(struct device)); > + ret[numdevices] = new; > + ret[numdevices + 1] = NULL; > + numdevices++; > + } > + } > storagedone: > > - if (type & DEVICE_NETWORK) { > - DIR *dir; > - struct dirent *ent; > - > - dir = opendir("/sys/class/net"); > - > - if (!dir) goto netdone; > - > - while ((ent = readdir(dir))) { > - char path[64]; > - int fd, type; > - char buf[64]; > - > - snprintf(path, 64, "/sys/class/net/%s/type", > ent->d_name); > - fd = open(path, O_RDONLY); > - if (fd == -1) > - continue; > - if (read(fd, buf, 63) <= 0) { > - close(fd); > - continue; > - } > - > - close(fd); > - errno = 0; > - type = strtol(buf, NULL, 10); > - > - if ((errno == ERANGE && (type == LONG_MIN || type == > LONG_MAX)) || > - (errno != 0 && type == 0)) { > - return NULL; > - } > - > - if (type != 1) > - continue; > - > - new = calloc(1, sizeof(struct device)); > - new->device = strdup(ent->d_name); > - /* FIXME */ > - snprintf(path, 64, "/sys/class/net/%s/address", > ent->d_name); > - fd = open(path, O_RDONLY); > - if (fd != -1) { > - memset(buf, '\0', 64); > - if (read(fd, buf, 63) > 0) { > - int i; > - for (i = (strlen(buf)-1); isspace(buf[i]); i--) > - buf[i] = '\0'; > - new->priv.hwaddr = strdup(buf); > - } > - } > - > - if (new->priv.hwaddr) { > - if (asprintf(&new->description, "Ethernet device %s - > %s", > - new->device, new->priv.hwaddr) == -1) { > - fprintf(stderr, "%s: %d: %s\n", __func__, > __LINE__, > - strerror(errno)); > - fflush(stderr); > - abort(); > - } > - } else { > - if (asprintf(&new->description, "Ethernet device > %s", > - new->device) == -1) { > - fprintf(stderr, "%s: %d: %s\n", __func__, > __LINE__, > - strerror(errno)); > - fflush(stderr); > - abort(); > - } > - } > - > - ret = realloc(ret, (numdevices+2) * sizeof(struct > device)); > - ret[numdevices] = new; > - ret[numdevices+1] = NULL; > - numdevices++; > - } > - } > + if (type & DEVICE_NETWORK) { > + DIR *dir; > + struct dirent *ent; > + > + dir = opendir("/sys/class/net"); > + > + if (!dir) > + goto netdone; > + > + while ((ent = readdir(dir))) { > + char path[64]; > + int fd, type; > + char buf[64]; > + > + snprintf(path, 64, "/sys/class/net/%s/type", > + ent->d_name); > + fd = open(path, O_RDONLY); > + if (fd == -1) > + continue; > + if (read(fd, buf, 63) <= 0) { > + close(fd); > + continue; > + } > + > + close(fd); > + errno = 0; > + type = strtol(buf, NULL, 10); > + > + if ((errno == ERANGE > + && (type == LONG_MIN || type == LONG_MAX)) > + || (errno != 0 && type == 0)) { > + return NULL; > + } > + > + if (type != 1) > + continue; > + > + new = calloc(1, sizeof(struct device)); > + new->device = strdup(ent->d_name); > + /* FIXME */ > + snprintf(path, 64, "/sys/class/net/%s/address", > + ent->d_name); > + fd = open(path, O_RDONLY); > + if (fd != -1) { > + memset(buf, '\0', 64); > + if (read(fd, buf, 63) > 0) { > + int i; > + for (i = (strlen(buf) - 1); > + isspace(buf[i]); i--) > + buf[i] = '\0'; > + new->priv.hwaddr = strdup(buf); > + } > + } > + > + if (new->priv.hwaddr) { > + if (asprintf > + (&new->description, > + "Ethernet device %s - %s", new->device, > + new->priv.hwaddr) == -1) { > + fprintf(stderr, "%s: %d: %s\n", > + __func__, __LINE__, > + strerror(errno)); > + fflush(stderr); > + abort(); > + } > + } else { > + if (asprintf > + (&new->description, "Ethernet device %s", > + new->device) == -1) { > + fprintf(stderr, "%s: %d: %s\n", > + __func__, __LINE__, > + strerror(errno)); > + fflush(stderr); > + abort(); > + } > + } > + > + ret = > + realloc(ret, > + (numdevices + 2) * sizeof(struct device)); > + ret[numdevices] = new; > + ret[numdevices + 1] = NULL; > + numdevices++; > + } > + } > netdone: > - return ret; > + return ret; > } > > - > /* vim:set sw=8 noet */ > diff --git a/isys/devices.h b/isys/devices.h > index 9f636ad..7262ce1 100644 > --- a/isys/devices.h > +++ b/isys/devices.h > @@ -21,20 +21,20 @@ > #define DEVICES_H > > enum deviceType { > - DEVICE_ANY = ~0, > - DEVICE_NETWORK = (1 << 0), > - DEVICE_DISK = (1 << 1), > - DEVICE_CDROM = (1 << 2) > + DEVICE_ANY = ~0, > + DEVICE_NETWORK = (1 << 0), > + DEVICE_DISK = (1 << 1), > + DEVICE_CDROM = (1 << 2) > }; > > struct device { > - char *device; > - char *description; > - enum deviceType type; > - union { > - char *hwaddr; > - int removable; > - } priv; > + char *device; > + char *description; > + enum deviceType type; > + union { > + char *hwaddr; > + int removable; > + } priv; > }; > > struct device **getDevices(enum deviceType type); > diff --git a/isys/eddsupport.c b/isys/eddsupport.c > index c2b7a3c..1f310f0 100644 > --- a/isys/eddsupport.c > +++ b/isys/eddsupport.c > @@ -36,7 +36,6 @@ > #include <sys/types.h> > #include <linux/types.h> > > - > #include "eddsupport.h" > #include "devices.h" > #include "isys.h" > @@ -47,30 +46,27 @@ > > #define HASH_TABLE_SIZE 17 > > - > -struct diskMapEntry{ > - uint32_t key; > - char *diskname; > - struct diskMapEntry *next; > +struct diskMapEntry { > + uint32_t key; > + char *diskname; > + struct diskMapEntry *next; > }; > > struct diskMapTable { > - struct diskMapEntry **table; > - int tableSize; > + struct diskMapEntry **table; > + int tableSize; > }; > > static struct diskMapTable *mbrSigToName = NULL; > static int diskHashInit = 0; > > - > - > -static struct diskMapTable* initializeHashTable(int); > +static struct diskMapTable *initializeHashTable(int); > static int insertHashItem(struct diskMapTable *, struct diskMapEntry > *); > -static struct diskMapEntry* lookupHashItem(struct diskMapTable *, > uint32_t); > -static int addToHashTable(struct diskMapTable *, uint32_t , char *); > -static struct device ** createDiskList(); > -static int mapBiosDisks(struct device ** , const char *); > -static int readDiskSig(char *, uint32_t *); > +static struct diskMapEntry *lookupHashItem(struct diskMapTable *, > uint32_t); > +static int addToHashTable(struct diskMapTable *, uint32_t, char *); > +static struct device **createDiskList(); > +static int mapBiosDisks(struct device **, const char *); > +static int readDiskSig(char *, uint32_t *); > static int readMbrSig(char *, uint32_t *); > > /* This is the top level function that creates a disk list present in > the > @@ -79,263 +75,274 @@ static int readMbrSig(char *, uint32_t *); > * corresponding hd/sd device names. Otherwise, we'll avoid mapping > drives. > */ > > -int probeBiosDisks() { > - struct device ** devices = NULL; > +int probeBiosDisks() > +{ > + struct device **devices = NULL; > > - devices = createDiskList(); > - if(!devices){ > + devices = createDiskList(); > + if (!devices) { > #ifdef STANDALONE > - fprintf(stderr, "No disks!\n"); > + fprintf(stderr, "No disks!\n"); > #endif > - return -1; > - } > + return -1; > + } > > - if(!mapBiosDisks(devices, EDD_DIR)){ > + if (!mapBiosDisks(devices, EDD_DIR)) { > #ifdef STANDALONE > - fprintf(stderr, "WARNING: couldn't map BIOS disks\n"); > + fprintf(stderr, "WARNING: couldn't map BIOS disks\n"); > #endif > - return -1; > - } > - return 0; > + return -1; > + } > + return 0; > } > > - > -static struct device ** createDiskList(){ > - return getDevices (DEVICE_DISK); > +static struct device **createDiskList() > +{ > + return getDevices(DEVICE_DISK); > } > > -static int readDiskSig(char *device, uint32_t *disksig) { > - int fd, rc; > - char devnodeName[64]; > +static int readDiskSig(char *device, uint32_t * disksig) > +{ > + int fd, rc; > + char devnodeName[64]; > > - snprintf(devnodeName, sizeof(devnodeName), "/dev/%s", device); > - fd = open(devnodeName, O_RDONLY); > - if (fd < 0) { > -#ifdef STANDALONE > - fprintf(stderr, "Error opening device %s: %s\n ", device, > - strerror(errno)); > -#endif > - return -errno; > - } > + snprintf(devnodeName, sizeof(devnodeName), "/dev/%s", device); > + fd = open(devnodeName, O_RDONLY); > + if (fd < 0) { > +#ifdef STANDALONE > + fprintf(stderr, "Error opening device %s: %s\n ", device, > + strerror(errno)); > +#endif > + return -errno; > + } > > - rc = lseek(fd, MBRSIG_OFFSET, SEEK_SET); > - if (rc < 0){ > - close(fd); > + rc = lseek(fd, MBRSIG_OFFSET, SEEK_SET); > + if (rc < 0) { > + close(fd); > > #ifdef STANDALONE > - fprintf(stderr, "Error seeking to MBRSIG_OFFSET in %s: %s\n", > > - device, strerror(errno)); > + fprintf(stderr, "Error seeking to MBRSIG_OFFSET in %s: %s\n", > + device, strerror(errno)); > #endif > - return -1; > - } > + return -1; > + } > > - rc = read(fd, disksig, sizeof(uint32_t)); > - if (rc < sizeof(uint32_t)) { > - close(fd); > + rc = read(fd, disksig, sizeof(uint32_t)); > + if (rc < sizeof(uint32_t)) { > + close(fd); > > #ifdef STANDALONE > - fprintf(stderr, "Failed to read signature from %s\n", > device); > + fprintf(stderr, "Failed to read signature from %s\n", device); > #endif > - return -1; > - } > + return -1; > + } > > - close(fd); > - return 0; > + close(fd); > + return 0; > } > > -static int mapBiosDisks(struct device** devices,const char *path) { > - DIR *dirHandle; > - struct dirent *entry; > - char * sigFileName; > - uint32_t mbrSig, biosNum, currentSig; > - struct device **currentDev, **foundDisk; > - int i, rc, ret, dm_nr, highest_dm; > - > - dirHandle = opendir(path); > - if(!dirHandle){ > +static int mapBiosDisks(struct device **devices, const char *path) > +{ > + DIR *dirHandle; > + struct dirent *entry; > + char *sigFileName; > + uint32_t mbrSig, biosNum, currentSig; > + struct device **currentDev, **foundDisk; > + int i, rc, ret, dm_nr, highest_dm; > + > + dirHandle = opendir(path); > + if (!dirHandle) { > #ifdef STANDALONE > - fprintf(stderr, "Failed to open directory %s: %s\n", path, > - strerror(errno)); > + fprintf(stderr, "Failed to open directory %s: %s\n", path, > + strerror(errno)); > #endif > - return 0; > - } > + return 0; > + } > > - mbrSigToName = initializeHashTable(HASH_TABLE_SIZE); > - if(!mbrSigToName){ > + mbrSigToName = initializeHashTable(HASH_TABLE_SIZE); > + if (!mbrSigToName) { > #ifdef STANDALONE > - fprintf(stderr, "Error initializing mbrSigToName table\n"); > + fprintf(stderr, "Error initializing mbrSigToName table\n"); > #endif > - closedir(dirHandle); > - return 0; > - } > - > - while ((entry = readdir(dirHandle)) != NULL) { > - if(!strncmp(entry->d_name,".",1) || > !strncmp(entry->d_name,"..",2)) { > - continue; > - } > - ret = sscanf((entry->d_name+9), "%x", &biosNum); > - > - sigFileName = malloc(strlen(path) + strlen(entry->d_name) + > 20); > - sprintf(sigFileName, "%s/%s/%s", path, entry->d_name, > SIG_FILE); > - if (readMbrSig(sigFileName, &mbrSig) == 0) { > - for (currentDev = devices, i = 0, foundDisk=NULL, > highest_dm=-1; > - (*currentDev) != NULL; > - currentDev++) { > - if (!(*currentDev)->device) > - continue; > - > - if ((rc=readDiskSig((*currentDev)->device, > ¤tSig)) < 0) { > - if (rc == -ENOMEDIUM || rc == -ENXIO) > - continue; > - closedir(dirHandle); > - return 0; > - } > - > - if (mbrSig == currentSig) { > - /* When we have a fakeraid setup we will find > multiple hits > - a number for the raw disks (1 when striping, 2 > when > - mirroring, more with raid on raid like raid 01 > or 10) > - and a number for the dm devices (normally only > one dm > - device will match, but more with raid on > raid). > - Since with raid on raid the last dm device > created > - will be the top layer raid, we want the > highest matching > - dm device. */ > - if (!strncmp((*currentDev)->device, "dm-", 3) && > - sscanf((*currentDev)->device+3, "%d", > &dm_nr) == 1) { > - if (dm_nr > highest_dm) { > - highest_dm = dm_nr; > - foundDisk=currentDev; > - i = 1; > - } > - } else if (!foundDisk || > - strncmp((*foundDisk)->device, "dm-", > 3)) { > - foundDisk=currentDev; > - i++; > - } > - } > - } > - > - if (i==1) { > - if(!addToHashTable(mbrSigToName, (uint32_t)biosNum, > - (*foundDisk)->device)) { > - closedir(dirHandle); > - return 0; > - } > - } > - } > - } > - closedir(dirHandle); > - return 1; > -} > - > - > -static int readMbrSig(char *filename, uint32_t *int_sig){ > - FILE* fh; > - > - fh = fopen(filename,"r"); > - if(fh == NULL) { > + closedir(dirHandle); > + return 0; > + } > + > + while ((entry = readdir(dirHandle)) != NULL) { > + if (!strncmp(entry->d_name, ".", 1) > + || !strncmp(entry->d_name, "..", 2)) { > + continue; > + } > + ret = sscanf((entry->d_name + 9), "%x", &biosNum); > + > + sigFileName = malloc(strlen(path) + strlen(entry->d_name) + 20); > + sprintf(sigFileName, "%s/%s/%s", path, entry->d_name, SIG_FILE); > + if (readMbrSig(sigFileName, &mbrSig) == 0) { > + for (currentDev = devices, i = 0, foundDisk = > + NULL, highest_dm = -1; (*currentDev) != NULL; > + currentDev++) { > + if (!(*currentDev)->device) > + continue; > + > + if ((rc = > + readDiskSig((*currentDev)->device, > + ¤tSig)) < 0) { > + if (rc == -ENOMEDIUM || rc == -ENXIO) > + continue; > + closedir(dirHandle); > + return 0; > + } > + > + if (mbrSig == currentSig) { > + /* When we have a fakeraid setup we will find multiple hits > + a number for the raw disks (1 when striping, 2 when > + mirroring, more with raid on raid like raid 01 or 10) > + and a number for the dm devices (normally only one dm > + device will match, but more with raid on raid). > + Since with raid on raid the last dm device created > + will be the top layer raid, we want the highest matching > + dm device. */ > + if (!strncmp > + ((*currentDev)->device, "dm-", 3) > + && sscanf((*currentDev)->device + 3, > + "%d", &dm_nr) == 1) { > + if (dm_nr > highest_dm) { > + highest_dm = dm_nr; > + foundDisk = currentDev; > + i = 1; > + } > + } else if (!foundDisk || > + strncmp((*foundDisk)->device, > + "dm-", 3)) { > + foundDisk = currentDev; > + i++; > + } > + } > + } > + > + if (i == 1) { > + if (!addToHashTable > + (mbrSigToName, (uint32_t) biosNum, > + (*foundDisk)->device)) { > + closedir(dirHandle); > + return 0; > + } > + } > + } > + } > + closedir(dirHandle); > + return 1; > +} > + > +static int readMbrSig(char *filename, uint32_t * int_sig) > +{ > + FILE *fh; > + > + fh = fopen(filename, "r"); > + if (fh == NULL) { > #ifdef STANDALONE > - fprintf(stderr, "Error opening mbr_signature file %s: %s\n", > filename, > - strerror(errno)); > + fprintf(stderr, "Error opening mbr_signature file %s: %s\n", > + filename, strerror(errno)); > #endif > - return -1; > - } > - fseek(fh, 0, SEEK_SET); > - if (fscanf(fh, "%x", int_sig) != 1) { > + return -1; > + } > + fseek(fh, 0, SEEK_SET); > + if (fscanf(fh, "%x", int_sig) != 1) { > #ifdef STANDALONE > - fprintf(stderr, "Error reading %s\n", filename); > + fprintf(stderr, "Error reading %s\n", filename); > #endif > - fclose(fh); > - return -1; > - } > - > - fclose(fh); > - return 0; > -} > + fclose(fh); > + return -1; > + } > > + fclose(fh); > + return 0; > +} > > -static struct diskMapTable* initializeHashTable(int size) { > - struct diskMapTable *hashTable; > +static struct diskMapTable *initializeHashTable(int size) > +{ > + struct diskMapTable *hashTable; > > - hashTable = malloc(sizeof(struct diskMapTable)); > - hashTable->tableSize = size; > - hashTable->table = malloc(sizeof(struct diskMapEntry *) * size); > - memset(hashTable->table,0,(sizeof(struct diskMapEntry *) * > size)); > - return hashTable; > + hashTable = malloc(sizeof(struct diskMapTable)); > + hashTable->tableSize = size; > + hashTable->table = malloc(sizeof(struct diskMapEntry *) * size); > + memset(hashTable->table, 0, (sizeof(struct diskMapEntry *) * > size)); > + return hashTable; > } > > - > static int insertHashItem(struct diskMapTable *hashTable, > - struct diskMapEntry *hashItem) { > - int index; > - > - index = (hashItem->key) % (hashTable->tableSize); > - > - if(hashTable->table[index] == NULL){ > - hashTable->table[index] = hashItem; > - return index; > - } else { > - hashItem->next = hashTable->table[index]; > - hashTable->table[index] = hashItem; > - return index; > - } > + struct diskMapEntry *hashItem) > +{ > + int index; > + > + index = (hashItem->key) % (hashTable->tableSize); > + > + if (hashTable->table[index] == NULL) { > + hashTable->table[index] = hashItem; > + return index; > + } else { > + hashItem->next = hashTable->table[index]; > + hashTable->table[index] = hashItem; > + return index; > + } > } > > - > -static struct diskMapEntry * lookupHashItem(struct diskMapTable > *hashTable, > - uint32_t itemKey) { > - int index; > - struct diskMapEntry *hashItem; > - > - index = itemKey % (hashTable->tableSize); > - for (hashItem = hashTable->table[index]; > - (hashItem != NULL) && (hashItem->key != itemKey); > - hashItem = hashItem->next) { > - ; > - } > - return hashItem; > +static struct diskMapEntry *lookupHashItem(struct diskMapTable > *hashTable, > + uint32_t itemKey) > +{ > + int index; > + struct diskMapEntry *hashItem; > + > + index = itemKey % (hashTable->tableSize); > + for (hashItem = hashTable->table[index]; > + (hashItem != NULL) && (hashItem->key != itemKey); > + hashItem = hashItem->next) { > + ; > + } > + return hashItem; > } > > +static int addToHashTable(struct diskMapTable *hashTable, > + uint32_t itemKey, char *diskName) > +{ > + int index; > + struct diskMapEntry *diskSigToNameEntry; > > -static int addToHashTable(struct diskMapTable *hashTable, > - uint32_t itemKey, char *diskName) { > - int index; > - struct diskMapEntry *diskSigToNameEntry; > + diskSigToNameEntry = malloc(sizeof(struct diskMapEntry)); > + diskSigToNameEntry->next = NULL; > + diskSigToNameEntry->key = itemKey; > + diskSigToNameEntry->diskname = diskName; > > - diskSigToNameEntry = malloc(sizeof(struct diskMapEntry)); > - diskSigToNameEntry->next = NULL; > - diskSigToNameEntry->key = itemKey; > - diskSigToNameEntry->diskname = diskName; > - > - if ((index = insertHashItem(hashTable, diskSigToNameEntry)) < > 0){ > + if ((index = insertHashItem(hashTable, diskSigToNameEntry)) < 0) { > #ifdef STANDALONE > - fprintf(stderr, "Unable to insert item\n"); > + fprintf(stderr, "Unable to insert item\n"); > #endif > - return 0; > - } else { > - return 1; > - } > + return 0; > + } else { > + return 1; > + } > } > > +char *getBiosDisk(char *biosStr) > +{ > + uint32_t biosNum; > + struct diskMapEntry *disk; > + int ret; > > -char * getBiosDisk(char *biosStr) { > - uint32_t biosNum; > - struct diskMapEntry * disk; > - int ret; > - > - if (diskHashInit == 0) { > - probeBiosDisks(); > - diskHashInit = 1; > - } > + if (diskHashInit == 0) { > + probeBiosDisks(); > + diskHashInit = 1; > + } > > - if (mbrSigToName == NULL) > - return NULL; > + if (mbrSigToName == NULL) > + return NULL; > > - ret = sscanf(biosStr,"%x",&biosNum); > - disk = lookupHashItem(mbrSigToName, biosNum); > - if (disk) return disk->diskname; > + ret = sscanf(biosStr, "%x", &biosNum); > + disk = lookupHashItem(mbrSigToName, biosNum); > + if (disk) > + return disk->diskname; > > - return NULL; > + return NULL; > } > > /* vim:set sw=8 noet */ > diff --git a/isys/eddsupport.h b/isys/eddsupport.h > index ec7d3f4..51427bd 100644 > --- a/isys/eddsupport.h > +++ b/isys/eddsupport.h > @@ -21,10 +21,8 @@ > #define EDDSUPPORT_H > > int probeBiosDisks(); > -char* getBiosDisk(char *); > +char *getBiosDisk(char *); > > #endif > > - > - > /* vim:set sw=8 noet */ > diff --git a/isys/ethtool.c b/isys/ethtool.c > index eb4e592..657c2f6 100644 > --- a/isys/ethtool.c > +++ b/isys/ethtool.c > @@ -33,89 +33,92 @@ > #include <linux/sockios.h> > #include "ethtool.h" > > -static int set_intf_up(struct ifreq ifr, int sock) { > - if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) { > - return (-1); > - } > - ifr.ifr_flags |= (IFF_UP | IFF_RUNNING); > - if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) { > - fprintf(stderr, "failed to bring up interface %s: %s", > ifr.ifr_name, > - strerror(errno)); > - return -1; > - } > - return (0); > +static int set_intf_up(struct ifreq ifr, int sock) > +{ > + if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) { > + return (-1); > + } > + ifr.ifr_flags |= (IFF_UP | IFF_RUNNING); > + if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) { > + fprintf(stderr, "failed to bring up interface %s: %s", > + ifr.ifr_name, strerror(errno)); > + return -1; > + } > + return (0); > } > > -int setEthtoolSettings(char * dev, ethtool_speed speed, > - ethtool_duplex duplex) { > - int sock, err; > - struct ethtool_cmd ecmd; > - struct ifreq ifr; > - > - if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { > - perror("Unable to create socket"); > - return -1; > - } > - > - /* Setup our control structures. */ > - memset(&ifr, 0, sizeof(ifr)); > - strcpy(ifr.ifr_name, dev); > - > - if (set_intf_up(ifr, sock) == -1) { > - fprintf(stderr, "unable to bring up interface %s: %s", dev, > - strerror(errno)); > - return -1; > - } > - > - ecmd.cmd = ETHTOOL_GSET; > - ifr.ifr_data = (caddr_t)&ecmd; > - err = ioctl(sock, SIOCETHTOOL, &ifr); > - if (err < 0) { > - perror("Unable to get settings via ethtool. Not setting"); > - return -1; > - } > - > - if (speed != ETHTOOL_SPEED_UNSPEC) > - ecmd.speed = speed; > - if (duplex != ETHTOOL_DUPLEX_UNSPEC) > - ecmd.duplex = duplex; > - if ((duplex != ETHTOOL_DUPLEX_UNSPEC) || (speed != > ETHTOOL_SPEED_UNSPEC)) > - ecmd.autoneg = AUTONEG_DISABLE; > - > - ecmd.cmd = ETHTOOL_SSET; > - ifr.ifr_data = (caddr_t)&ecmd; > - err = ioctl(sock, SIOCETHTOOL, &ifr); > - if (err < 0) { > - // perror("Unable to set settings via ethtool. Not > setting"); > - return -1; > - } > - > - return 0; > +int setEthtoolSettings(char *dev, ethtool_speed speed, ethtool_duplex > duplex) > +{ > + int sock, err; > + struct ethtool_cmd ecmd; > + struct ifreq ifr; > + > + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { > + perror("Unable to create socket"); > + return -1; > + } > + > + /* Setup our control structures. */ > + memset(&ifr, 0, sizeof(ifr)); > + strcpy(ifr.ifr_name, dev); > + > + if (set_intf_up(ifr, sock) == -1) { > + fprintf(stderr, "unable to bring up interface %s: %s", dev, > + strerror(errno)); > + return -1; > + } > + > + ecmd.cmd = ETHTOOL_GSET; > + ifr.ifr_data = (caddr_t) & ecmd; > + err = ioctl(sock, SIOCETHTOOL, &ifr); > + if (err < 0) { > + perror("Unable to get settings via ethtool. Not setting"); > + return -1; > + } > + > + if (speed != ETHTOOL_SPEED_UNSPEC) > + ecmd.speed = speed; > + if (duplex != ETHTOOL_DUPLEX_UNSPEC) > + ecmd.duplex = duplex; > + if ((duplex != ETHTOOL_DUPLEX_UNSPEC) > + || (speed != ETHTOOL_SPEED_UNSPEC)) > + ecmd.autoneg = AUTONEG_DISABLE; > + > + ecmd.cmd = ETHTOOL_SSET; > + ifr.ifr_data = (caddr_t) & ecmd; > + err = ioctl(sock, SIOCETHTOOL, &ifr); > + if (err < 0) { > + // perror("Unable to set settings via ethtool. Not > setting"); > + return -1; > + } > + > + return 0; > } > > -int identifyNIC(char *iface, int seconds) { > - int sock; > - struct ethtool_value edata; > - struct ifreq ifr; > +int identifyNIC(char *iface, int seconds) > +{ > + int sock; > + struct ethtool_value edata; > + struct ifreq ifr; > > - if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { > - perror("Unable to create socket"); > - return -1; > - } > + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { > + perror("Unable to create socket"); > + return -1; > + } > > - memset(&ifr, 0, sizeof(ifr)); > - memset(&edata, 0, sizeof(edata)); > + memset(&ifr, 0, sizeof(ifr)); > + memset(&edata, 0, sizeof(edata)); > > - strcpy(ifr.ifr_name, iface); > - edata.cmd = ETHTOOL_PHYS_ID; > - edata.data = seconds; > - ifr.ifr_data = (caddr_t) &edata; > + strcpy(ifr.ifr_name, iface); > + edata.cmd = ETHTOOL_PHYS_ID; > + edata.data = seconds; > + ifr.ifr_data = (caddr_t) & edata; > > - if (ioctl(sock, SIOCETHTOOL, &ifr) < 0) { > - perror("Unable to identify NIC"); > - } > + if (ioctl(sock, SIOCETHTOOL, &ifr) < 0) { > + perror("Unable to identify NIC"); > + } > > - return 0; > + return 0; > } > > /* vim:set sw=8 noet */ > diff --git a/isys/ethtool.h b/isys/ethtool.h > index e661ceb..d63177e 100644 > --- a/isys/ethtool.h > +++ b/isys/ethtool.h > @@ -26,16 +26,18 @@ > /* returns 1 for link, 0 for no link, -1 for unknown */ > int get_link_status(char *ifname); > > -typedef enum ethtool_speed_t { ETHTOOL_SPEED_UNSPEC = -1, > - ETHTOOL_SPEED_10 = SPEED_10, > - ETHTOOL_SPEED_100 = SPEED_100, > - ETHTOOL_SPEED_1000 = SPEED_1000 } > ethtool_speed; > -typedef enum ethtool_duplex_t { ETHTOOL_DUPLEX_UNSPEC = -1, > - ETHTOOL_DUPLEX_HALF = DUPLEX_HALF, > - ETHTOOL_DUPLEX_FULL = DUPLEX_FULL } > ethtool_duplex; > +typedef enum ethtool_speed_t { ETHTOOL_SPEED_UNSPEC = -1, > + ETHTOOL_SPEED_10 = SPEED_10, > + ETHTOOL_SPEED_100 = SPEED_100, > + ETHTOOL_SPEED_1000 = SPEED_1000 > +} ethtool_speed; > +typedef enum ethtool_duplex_t { ETHTOOL_DUPLEX_UNSPEC = -1, > + ETHTOOL_DUPLEX_HALF = DUPLEX_HALF, > + ETHTOOL_DUPLEX_FULL = DUPLEX_FULL > +} ethtool_duplex; > > /* set ethtool settings */ > -int setEthtoolSettings(char * dev, ethtool_speed speed, > ethtool_duplex duplex); > +int setEthtoolSettings(char *dev, ethtool_speed speed, ethtool_duplex > duplex); > int identifyNIC(char *iface, int seconds); > > #endif > diff --git a/isys/iface.c b/isys/iface.c > index 1af53ef..cb48236 100644 > --- a/isys/iface.c > +++ b/isys/iface.c > @@ -63,93 +63,97 @@ static int _iface_redirect_io(char *device, int > fd, int mode); > /* > * Return a libnl handle for NETLINK_ROUTE. > */ > -static struct nl_handle *_iface_get_handle(void) { > - struct nl_handle *handle = NULL; > +static struct nl_handle *_iface_get_handle(void) > +{ > + struct nl_handle *handle = NULL; > > - if ((handle = nl_handle_alloc()) == NULL) { > - return NULL; > - } > + if ((handle = nl_handle_alloc()) == NULL) { > + return NULL; > + } > > - if (nl_connect(handle, NETLINK_ROUTE)) { > - nl_handle_destroy(handle); > - return NULL; > - } > + if (nl_connect(handle, NETLINK_ROUTE)) { > + nl_handle_destroy(handle); > + return NULL; > + } > > - return handle; > + return handle; > } > > /* > * Return an NETLINK_ROUTE cache. > */ > -static struct nl_cache *_iface_get_link_cache(struct nl_handle > **handle) { > - struct nl_cache *cache = NULL; > +static struct nl_cache *_iface_get_link_cache(struct nl_handle > **handle) > +{ > + struct nl_cache *cache = NULL; > > - if ((*handle = _iface_get_handle()) == NULL) { > - return NULL; > - } > + if ((*handle = _iface_get_handle()) == NULL) { > + return NULL; > + } > > - if ((cache = rtnl_link_alloc_cache(*handle)) == NULL) { > - nl_close(*handle); > - nl_handle_destroy(*handle); > - return NULL; > - } > + if ((cache = rtnl_link_alloc_cache(*handle)) == NULL) { > + nl_close(*handle); > + nl_handle_destroy(*handle); > + return NULL; > + } > > - return cache; > + return cache; > } > > /* > * Determine if a struct in_addr or struct in6_addr contains a valid > address. > */ > -static int _iface_have_valid_addr(void *addr, int family, int length) > { > - char buf[length+1]; > - > - if ((addr == NULL) || (family != AF_INET && family != AF_INET6)) > { > - return 0; > - } > - > - memset(buf, '\0', sizeof(buf)); > - > - if (inet_ntop(family, addr, buf, length) == NULL) { > - return 0; > - } else { > - /* check for unknown addresses */ > - if (family == AF_INET) { > - if (!strncmp(buf, "0.0.0.0", 7)) { > - return 0; > - } > - } else if (family == AF_INET6) { > - if (!strncmp(buf, "::", 2)) { > - return 0; > - } > - } > - } > - > - return 1; > +static int _iface_have_valid_addr(void *addr, int family, int > length) > +{ > + char buf[length + 1]; > + > + if ((addr == NULL) || (family != AF_INET && family != AF_INET6)) { > + return 0; > + } > + > + memset(buf, '\0', sizeof(buf)); > + > + if (inet_ntop(family, addr, buf, length) == NULL) { > + return 0; > + } else { > + /* check for unknown addresses */ > + if (family == AF_INET) { > + if (!strncmp(buf, "0.0.0.0", 7)) { > + return 0; > + } > + } else if (family == AF_INET6) { > + if (!strncmp(buf, "::", 2)) { > + return 0; > + } > + } > + } > + > + return 1; > } > > /* > * Redirect I/O to another device (e.g., stdout to /dev/tty5) > */ > -int _iface_redirect_io(char *device, int fd, int mode) { > - int io = -1; > +int _iface_redirect_io(char *device, int fd, int mode) > +{ > + int io = -1; > > - if ((io = open(device, mode)) == -1) { > - return 1; > - } > + if ((io = open(device, mode)) == -1) { > + return 1; > + } > > - if (close(fd) == -1) { > - return 2; > - } > + if (close(fd) == -1) { > + return 2; > + } > > - if (dup2(io, fd) == -1) { > - return 3; > - } > + if (dup2(io, fd) == -1) { > + return 3; > + } > > - if (close(io) == -1) { > - return 4; > - } > + if (close(io) == -1) { > + return 4; > + } > > - return 0; > + return 0; > } > > /* > @@ -157,388 +161,402 @@ int _iface_redirect_io(char *device, int fd, > int mode) { > * return the IP address in human readable format (i.e., the output > from > * inet_ntop()). Return NULL for no match or error. > */ > -char *iface_ip2str(char *ifname, int family) { > - int i; > - NMClient *client = NULL; > - NMIP4Config *ip4config = NULL; > - NMIP4Address *ipaddr = NULL; > - NMDevice *candidate = NULL; > - struct in_addr tmp_addr; > - const GPtrArray *devices; > - const char *iface; > - char ipstr[INET_ADDRSTRLEN+1]; > - > - if (ifname == NULL) { > - return NULL; > - } > - > - /* DCFIXME: add IPv6 once NM gains support */ > - if (family != AF_INET) { > - return NULL; > - } > - > - g_type_init(); > - > - client = nm_client_new(); > - if (!client) { > - return NULL; > - } > - > - if (nm_client_get_state(client) != NM_STATE_CONNECTED) { > - g_object_unref(client); > - return NULL; > - } > - > - devices = nm_client_get_devices(client); > - for (i=0; i < devices->len; i++) { > - candidate = g_ptr_array_index(devices, i); > - iface = nm_device_get_iface(candidate); > - > - if (nm_device_get_state(candidate) != > NM_DEVICE_STATE_ACTIVATED) > - continue; > - > - if (!iface || strcmp(iface, ifname)) > - continue; > - > - if (!(ip4config = nm_device_get_ip4_config(candidate))) > - continue; > - > - if (!(ipaddr = > nm_ip4_config_get_addresses(ip4config)->data)) > - continue; > - > - memset(&ipstr, '\0', sizeof(ipstr)); > - tmp_addr.s_addr = nm_ip4_address_get_address(ipaddr); > - > - if (inet_ntop(AF_INET, &tmp_addr, ipstr, INET_ADDRSTRLEN) == > NULL) { > - g_object_unref(client); > - return NULL; > - } > - > - g_object_unref(client); > - return g_strdup(ipstr); > - } > - > - g_object_unref(client); > - return NULL; > +char *iface_ip2str(char *ifname, int family) > +{ > + int i; > + NMClient *client = NULL; > + NMIP4Config *ip4config = NULL; > + NMIP4Address *ipaddr = NULL; > + NMDevice *candidate = NULL; > + struct in_addr tmp_addr; > + const GPtrArray *devices; > + const char *iface; > + char ipstr[INET_ADDRSTRLEN + 1]; > + > + if (ifname == NULL) { > + return NULL; > + } > + > + /* DCFIXME: add IPv6 once NM gains support */ > + if (family != AF_INET) { > + return NULL; > + } > + > + g_type_init(); > + > + client = nm_client_new(); > + if (!client) { > + return NULL; > + } > + > + if (nm_client_get_state(client) != NM_STATE_CONNECTED) { > + g_object_unref(client); > + return NULL; > + } > + > + devices = nm_client_get_devices(client); > + for (i = 0; i < devices->len; i++) { > + candidate = g_ptr_array_index(devices, i); > + iface = nm_device_get_iface(candidate); > + > + if (nm_device_get_state(candidate) != NM_DEVICE_STATE_ACTIVATED) > + continue; > + > + if (!iface || strcmp(iface, ifname)) > + continue; > + > + if (!(ip4config = nm_device_get_ip4_config(candidate))) > + continue; > + > + if (!(ipaddr = nm_ip4_config_get_addresses(ip4config)->data)) > + continue; > + > + memset(&ipstr, '\0', sizeof(ipstr)); > + tmp_addr.s_addr = nm_ip4_address_get_address(ipaddr); > + > + if (inet_ntop(AF_INET, &tmp_addr, ipstr, INET_ADDRSTRLEN) == > + NULL) { > + g_object_unref(client); > + return NULL; > + } > + > + g_object_unref(client); > + return g_strdup(ipstr); > + } > + > + g_object_unref(client); > + return NULL; > } > > /* Given an interface's MAC address, return the name (e.g., eth0) in > human > * readable format. Return NULL for no match > */ > -char *iface_mac2device(char *mac) { > - struct nl_handle *handle = NULL; > - struct nl_cache *cache = NULL; > - struct rtnl_link *link = NULL; > - struct nl_addr *mac_as_nl_addr = NULL; > - char *retval = NULL; > - int i, n; > - > - if (mac == NULL) { > - return NULL; > - } > - > - if ((mac_as_nl_addr = nl_addr_parse(mac, AF_LLC)) == NULL) { > - return NULL; > - } > - > - if ((cache = _iface_get_link_cache(&handle)) == NULL) { > - return NULL; > - } > - > - n = nl_cache_nitems(cache); > - for (i = 0; i <= n; i++) { > - struct nl_addr *addr; > - > - if ((link = rtnl_link_get(cache, i)) == NULL) { > - continue; > - } > - > - addr = rtnl_link_get_addr(link); > - > - if (!nl_addr_cmp(mac_as_nl_addr, addr)) { > - retval = strdup(rtnl_link_get_name(link)); > - rtnl_link_put(link); > - break; > - } > - > - rtnl_link_put(link); > - } > - > - nl_close(handle); > - nl_handle_destroy(handle); > - > - return retval; > +char *iface_mac2device(char *mac) > +{ > + struct nl_handle *handle = NULL; > + struct nl_cache *cache = NULL; > + struct rtnl_link *link = NULL; > + struct nl_addr *mac_as_nl_addr = NULL; > + char *retval = NULL; > + int i, n; > + > + if (mac == NULL) { > + return NULL; > + } > + > + if ((mac_as_nl_addr = nl_addr_parse(mac, AF_LLC)) == NULL) { > + return NULL; > + } > + > + if ((cache = _iface_get_link_cache(&handle)) == NULL) { > + return NULL; > + } > + > + n = nl_cache_nitems(cache); > + for (i = 0; i <= n; i++) { > + struct nl_addr *addr; > + > + if ((link = rtnl_link_get(cache, i)) == NULL) { > + continue; > + } > + > + addr = rtnl_link_get_addr(link); > + > + if (!nl_addr_cmp(mac_as_nl_addr, addr)) { > + retval = strdup(rtnl_link_get_name(link)); > + rtnl_link_put(link); > + break; > + } > + > + rtnl_link_put(link); > + } > + > + nl_close(handle); > + nl_handle_destroy(handle); > + > + return retval; > } > > /* > * Given an interface name (e.g., eth0), return the MAC address in > human > * readable format (e.g., 00:11:52:12:D9:A0). Return NULL for no > match. > */ > -char *iface_mac2str(char *ifname) { > - int buflen = 20; > - char *buf = NULL; > - struct nl_handle *handle = NULL; > - struct nl_cache *cache = NULL; > - struct rtnl_link *link = NULL; > - struct nl_addr *addr = NULL; > - > - if (ifname == NULL) { > - return NULL; > - } > - > - if ((cache = _iface_get_link_cache(&handle)) == NULL) { > - return NULL; > - } > - > - if ((link = rtnl_link_get_by_name(cache, ifname)) == NULL) { > - goto mac2str_error2; > - } > - > - if ((addr = rtnl_link_get_addr(link)) == NULL) { > - goto mac2str_error3; > - } > - > - if ((buf = calloc(sizeof(char *), buflen)) == NULL) { > - goto mac2str_error4; > - } > - > - if ((buf = nl_addr2str(addr, buf, buflen)) != NULL) { > - buf = str2upper(buf); > - } > +char *iface_mac2str(char *ifname) > +{ > + int buflen = 20; > + char *buf = NULL; > + struct nl_handle *handle = NULL; > + struct nl_cache *cache = NULL; > + struct rtnl_link *link = NULL; > + struct nl_addr *addr = NULL; > + > + if (ifname == NULL) { > + return NULL; > + } > + > + if ((cache = _iface_get_link_cache(&handle)) == NULL) { > + return NULL; > + } > + > + if ((link = rtnl_link_get_by_name(cache, ifname)) == NULL) { > + goto mac2str_error2; > + } > + > + if ((addr = rtnl_link_get_addr(link)) == NULL) { > + goto mac2str_error3; > + } > + > + if ((buf = calloc(sizeof(char *), buflen)) == NULL) { > + goto mac2str_error4; > + } > + > + if ((buf = nl_addr2str(addr, buf, buflen)) != NULL) { > + buf = str2upper(buf); > + } > > mac2str_error4: > - nl_addr_destroy(addr); > + nl_addr_destroy(addr); > mac2str_error3: > - rtnl_link_put(link); > + rtnl_link_put(link); > mac2str_error2: > - nl_close(handle); > - nl_handle_destroy(handle); > + nl_close(handle); > + nl_handle_destroy(handle); > > - return buf; > + return buf; > } > > /* > * Convert an IPv4 CIDR prefix to a dotted-quad netmask. Return NULL > on > * failure. > */ > -struct in_addr *iface_prefix2netmask(int prefix) { > - int mask = 0; > - char *buf = NULL; > - struct in_addr *ret; > +struct in_addr *iface_prefix2netmask(int prefix) > +{ > + int mask = 0; > + char *buf = NULL; > + struct in_addr *ret; > > - if ((buf = calloc(sizeof(char *), INET_ADDRSTRLEN + 1)) == NULL) > { > - return NULL; > - } > + if ((buf = calloc(sizeof(char *), INET_ADDRSTRLEN + 1)) == NULL) { > + return NULL; > + } > > - mask = htonl(~((1 << (32 - prefix)) - 1)); > + mask = htonl(~((1 << (32 - prefix)) - 1)); > > - if (inet_ntop(AF_INET, (struct in_addr *) &mask, buf, > - INET_ADDRSTRLEN) == NULL) { > - return NULL; > - } > + if (inet_ntop(AF_INET, (struct in_addr *)&mask, buf, > + INET_ADDRSTRLEN) == NULL) { > + return NULL; > + } > > - if ((ret = calloc(sizeof(struct in_addr), 1)) == NULL) { > - return NULL; > - } > + if ((ret = calloc(sizeof(struct in_addr), 1)) == NULL) { > + return NULL; > + } > > - memcpy(ret, (struct in_addr *) &mask, sizeof(struct in_addr)); > - return ret; > + memcpy(ret, (struct in_addr *)&mask, sizeof(struct in_addr)); > + return ret; > } > > /* > * Initialize a new iface_t structure to default values. > */ > -void iface_init_iface_t(iface_t *iface) { > - int i; > - > - memset(&iface->device, '\0', sizeof(iface->device)); > - memset(&iface->ipaddr, 0, sizeof(iface->ipaddr)); > - memset(&iface->netmask, 0, sizeof(iface->netmask)); > - memset(&iface->broadcast, 0, sizeof(iface->broadcast)); > - memset(&iface->ip6addr, 0, sizeof(iface->ip6addr)); > - memset(&iface->gateway, 0, sizeof(iface->gateway)); > - memset(&iface->gateway6, 0, sizeof(iface->gateway6)); > - > - for (i = 0; i < MAXNS; i++) { > - iface->dns[i] = NULL; > - } > - > - iface->macaddr = NULL; > - iface->ip6prefix = 0; > - iface->nextserver = NULL; > - iface->bootfile = NULL; > - iface->numdns = 0; > - iface->hostname = NULL; > - iface->domain = NULL; > - iface->search = NULL; > - iface->dhcptimeout = 0; > - iface->vendorclass = NULL; > - iface->ssid = NULL; > - iface->wepkey = NULL; > - iface->mtu = 0; > - iface->subchannels = NULL; > - iface->portname = NULL; > - iface->peerid = NULL; > - iface->nettype = NULL; > - iface->ctcprot = NULL; > - iface->layer2 = NULL; > - iface->portno = NULL; > - iface->flags = 0; > - iface->ipv4method = IPV4_UNUSED_METHOD; > - iface->ipv6method = IPV6_UNUSED_METHOD; > - > - return; > +void iface_init_iface_t(iface_t * iface) > +{ > + int i; > + > + memset(&iface->device, '\0', sizeof(iface->device)); > + memset(&iface->ipaddr, 0, sizeof(iface->ipaddr)); > + memset(&iface->netmask, 0, sizeof(iface->netmask)); > + memset(&iface->broadcast, 0, sizeof(iface->broadcast)); > + memset(&iface->ip6addr, 0, sizeof(iface->ip6addr)); > + memset(&iface->gateway, 0, sizeof(iface->gateway)); > + memset(&iface->gateway6, 0, sizeof(iface->gateway6)); > + > + for (i = 0; i < MAXNS; i++) { > + iface->dns[i] = NULL; > + } > + > + iface->macaddr = NULL; > + iface->ip6prefix = 0; > + iface->nextserver = NULL; > + iface->bootfile = NULL; > + iface->numdns = 0; > + iface->hostname = NULL; > + iface->domain = NULL; > + iface->search = NULL; > + iface->dhcptimeout = 0; > + iface->vendorclass = NULL; > + iface->ssid = NULL; > + iface->wepkey = NULL; > + iface->mtu = 0; > + iface->subchannels = NULL; > + iface->portname = NULL; > + iface->peerid = NULL; > + iface->nettype = NULL; > + iface->ctcprot = NULL; > + iface->layer2 = NULL; > + iface->portno = NULL; > + iface->flags = 0; > + iface->ipv4method = IPV4_UNUSED_METHOD; > + iface->ipv6method = IPV6_UNUSED_METHOD; > + > + return; > } > > /* > * Given a pointer to a struct in_addr, return 1 if it contains a > valid > * address, 0 otherwise. > */ > -int iface_have_in_addr(struct in_addr *addr) { > - return _iface_have_valid_addr(addr, AF_INET, INET_ADDRSTRLEN); > +int iface_have_in_addr(struct in_addr *addr) > +{ > + return _iface_have_valid_addr(addr, AF_INET, INET_ADDRSTRLEN); > } > > /* > * Given a pointer to a struct in6_addr, return 1 if it contains a > valid > * address, 0 otherwise. > */ > -int iface_have_in6_addr(struct in6_addr *addr6) { > - return _iface_have_valid_addr(addr6, AF_INET6, > INET6_ADDRSTRLEN); > +int iface_have_in6_addr(struct in6_addr *addr6) > +{ > + return _iface_have_valid_addr(addr6, AF_INET6, INET6_ADDRSTRLEN); > } > > /* Check if NM has an active connection */ > -gboolean is_nm_connected(void) { > - NMState state; > - NMClient *client = NULL; > +gboolean is_nm_connected(void) > +{ > + NMState state; > + NMClient *client = NULL; > > - g_type_init(); > + g_type_init(); > > - client = nm_client_new(); > - if (!client) > - return FALSE; > + client = nm_client_new(); > + if (!client) > + return FALSE; > > - state = nm_client_get_state(client); > - g_object_unref(client); > + state = nm_client_get_state(client); > + g_object_unref(client); > > - if (state == NM_STATE_CONNECTED) > - return TRUE; > - else > - return FALSE; > + if (state == NM_STATE_CONNECTED) > + return TRUE; > + else > + return FALSE; > } > > /* Check if NM is already running */ > -gboolean is_nm_running(void) { > - gboolean running; > - NMClient *client = NULL; > +gboolean is_nm_running(void) > +{ > + gboolean running; > + NMClient *client = NULL; > > - g_type_init(); > + g_type_init(); > > - client = nm_client_new(); > - if (!client) > - return FALSE; > + client = nm_client_new(); > + if (!client) > + return FALSE; > > - running = nm_client_get_manager_running(client); > - g_object_unref(client); > - return running; > + running = nm_client_get_manager_running(client); > + g_object_unref(client); > + return running; > } > > /* > * Wait for NetworkManager to appear on the system bus > */ > -int wait_for_nm(void) { > - int count = 0; > +int wait_for_nm(void) > +{ > + int count = 0; > > - /* send message and block until a reply or error comes back */ > - while (count < 45) { > - if (is_nm_running()) > - return 0; > + /* send message and block until a reply or error comes back */ > + while (count < 45) { > + if (is_nm_running()) > + return 0; > > - sleep(1); > - count++; > - } > + sleep(1); > + count++; > + } > > - return 1; > + return 1; > } > > /* > * Start NetworkManager -- requires that you have already written out > the > * control files in /etc/sysconfig for the interface. > */ > -int iface_start_NetworkManager(void) { > - pid_t pid; > - > - if (is_nm_running()) > - return 0; /* already running */ > - > - /* Start NetworkManager */ > - pid = fork(); > - if (pid == 0) { > - if (setpgrp() == -1) { > - exit(1); > - } > - > - if (_iface_redirect_io("/dev/null", STDIN_FILENO, O_RDONLY) > || > - _iface_redirect_io(OUTPUT_TERMINAL, STDOUT_FILENO, > O_WRONLY) || > - _iface_redirect_io(OUTPUT_TERMINAL, STDERR_FILENO, > O_WRONLY)) { > - exit(2); > - } > - > - if (execl(NETWORKMANAGER, NETWORKMANAGER, > - > "--pid-file=/var/run/NetworkManager/NetworkManager.pid", > - NULL) == -1) { > - exit(3); > - } > - } else if (pid == -1) { > - return 1; > - } else { > - return wait_for_nm(); > - } > - > - return 0; > +int iface_start_NetworkManager(void) > +{ > + pid_t pid; > + > + if (is_nm_running()) > + return 0; /* already running */ > + > + /* Start NetworkManager */ > + pid = fork(); > + if (pid == 0) { > + if (setpgrp() == -1) { > + exit(1); > + } > + > + if (_iface_redirect_io("/dev/null", STDIN_FILENO, O_RDONLY) || > + _iface_redirect_io(OUTPUT_TERMINAL, STDOUT_FILENO, O_WRONLY) > + || _iface_redirect_io(OUTPUT_TERMINAL, STDERR_FILENO, > + O_WRONLY)) { > + exit(2); > + } > + > + if (execl(NETWORKMANAGER, NETWORKMANAGER, > + "--pid-file=/var/run/NetworkManager/NetworkManager.pid", > + NULL) == -1) { > + exit(3); > + } > + } else if (pid == -1) { > + return 1; > + } else { > + return wait_for_nm(); > + } > + > + return 0; > } > > /* > * Set the MTU on the specified device. > */ > -int iface_set_interface_mtu(char *ifname, int mtu) { > - int ret = 0; > - struct nl_handle *handle = NULL; > - struct nl_cache *cache = NULL; > - struct rtnl_link *link = NULL; > - struct rtnl_link *request = NULL; > - > - if (ifname == NULL) { > - return -1; > - } > - > - if (mtu <= 0) { > - return -2; > - } > - > - if ((cache = _iface_get_link_cache(&handle)) == NULL) { > - return -3; > - } > - > - if ((link = rtnl_link_get_by_name(cache, ifname)) == NULL) { > - ret = -4; > - goto ifacemtu_error1; > - } > - > - request = rtnl_link_alloc(); > - rtnl_link_set_mtu(request, mtu); > - > - if (rtnl_link_change(handle, link, request, 0)) { > - ret = -5; > - goto ifacemtu_error2; > - } > +int iface_set_interface_mtu(char *ifname, int mtu) > +{ > + int ret = 0; > + struct nl_handle *handle = NULL; > + struct nl_cache *cache = NULL; > + struct rtnl_link *link = NULL; > + struct rtnl_link *request = NULL; > + > + if (ifname == NULL) { > + return -1; > + } > + > + if (mtu <= 0) { > + return -2; > + } > + > + if ((cache = _iface_get_link_cache(&handle)) == NULL) { > + return -3; > + } > + > + if ((link = rtnl_link_get_by_name(cache, ifname)) == NULL) { > + ret = -4; > + goto ifacemtu_error1; > + } > + > + request = rtnl_link_alloc(); > + rtnl_link_set_mtu(request, mtu); > + > + if (rtnl_link_change(handle, link, request, 0)) { > + ret = -5; > + goto ifacemtu_error2; > + } > > ifacemtu_error2: > - rtnl_link_put(link); > + rtnl_link_put(link); > ifacemtu_error1: > - nl_close(handle); > - nl_handle_destroy(handle); > + nl_close(handle); > + nl_handle_destroy(handle); > > - return ret; > + return ret; > } > > /* vim:set sw=8 noet */ > diff --git a/isys/iface.h b/isys/iface.h > index 17696ec..1fe9ecc 100644 > --- a/isys/iface.h > +++ b/isys/iface.h > @@ -31,9 +31,12 @@ > /* Enumerated types used in iface.c as well as loader's network code > */ > enum { IPUNUSED, IPV4, IPV6 }; > > -enum { IPV4_UNUSED_METHOD, IPV4_DHCP_METHOD, IPV4_MANUAL_METHOD, > IPV4_IBFT_METHOD, IPV4_IBFT_DHCP_METHOD }; > +enum { IPV4_UNUSED_METHOD, IPV4_DHCP_METHOD, IPV4_MANUAL_METHOD, > + IPV4_IBFT_METHOD, IPV4_IBFT_DHCP_METHOD > +}; > enum { IPV6_UNUSED_METHOD, IPV6_AUTO_METHOD, IPV6_DHCP_METHOD, > - IPV6_MANUAL_METHOD }; > + IPV6_MANUAL_METHOD > +}; > > #define IPV4_FIRST_METHOD IPV4_DHCP_METHOD > #define IPV4_LAST_METHOD IPV4_MANUAL_METHOD > @@ -50,59 +53,59 @@ enum { IPV6_UNUSED_METHOD, IPV6_AUTO_METHOD, > IPV6_DHCP_METHOD, > > /* Per-interface configuration information */ > typedef struct _iface_t { > - /* device name (e.g., eth0) */ > - char device[IF_NAMESIZE]; > - > - /* MAC address as xx:xx:xx:xx:xx:xx */ > - char *macaddr; > - > - /* IPv4 (store addresses in in_addr format, use inet_pton() to > display) */ > - struct in_addr ipaddr; > - struct in_addr netmask; > - struct in_addr broadcast; > - > - /* IPv6 (store addresses in in6_addr format, prefix is just an > int) */ > - struct in6_addr ip6addr; > - int ip6prefix; > - > - /* Gateway settings */ > - struct in_addr gateway; > - struct in6_addr gateway6; > - > - /* BOOTP (these can be IPv4 or IPv6, store human-readable version > as str) */ > - char *nextserver; > - char *bootfile; > - > - /* DNS (these can be IPv4 or IPv6, store human-readable version > as str) */ > - char *dns[MAXNS]; > - int numdns; > - char *hostname; > - char *domain; > - char *search; > - > - /* Misc DHCP settings */ > - int dhcptimeout; > - char *vendorclass; > - > - /* Wireless settings */ > - char *ssid; > - char *wepkey; > - > - /* s390 specifics */ > - int mtu; > - char *subchannels; > - char *portname; > - char *peerid; > - char *nettype; > - char *ctcprot; > - char *layer2; > - char *portno; > - > - /* flags */ > - uint64_t flags; > - int ipv4method; > - int ipv6method; > - int isiBFT; > + /* device name (e.g., eth0) */ > + char device[IF_NAMESIZE]; > + > + /* MAC address as xx:xx:xx:xx:xx:xx */ > + char *macaddr; > + > + /* IPv4 (store addresses in in_addr format, use inet_pton() to > display) */ > + struct in_addr ipaddr; > + struct in_addr netmask; > + struct in_addr broadcast; > + > + /* IPv6 (store addresses in in6_addr format, prefix is just an int) > */ > + struct in6_addr ip6addr; > + int ip6prefix; > + > + /* Gateway settings */ > + struct in_addr gateway; > + struct in6_addr gateway6; > + > + /* BOOTP (these can be IPv4 or IPv6, store human-readable version as > str) */ > + char *nextserver; > + char *bootfile; > + > + /* DNS (these can be IPv4 or IPv6, store human-readable version as > str) */ > + char *dns[MAXNS]; > + int numdns; > + char *hostname; > + char *domain; > + char *search; > + > + /* Misc DHCP settings */ > + int dhcptimeout; > + char *vendorclass; > + > + /* Wireless settings */ > + char *ssid; > + char *wepkey; > + > + /* s390 specifics */ > + int mtu; > + char *subchannels; > + char *portname; > + char *peerid; > + char *nettype; > + char *ctcprot; > + char *layer2; > + char *portno; > + > + /* flags */ > + uint64_t flags; > + int ipv4method; > + int ipv6method; > + int isiBFT; > } iface_t; > > /* Function prototypes */ > diff --git a/isys/imount.c b/isys/imount.c > index 1dffa54..a9db2c9 100644 > --- a/isys/imount.c > +++ b/isys/imount.c > @@ -32,223 +32,235 @@ > > #define _(foo) foo > > -static int mkdirIfNone(char * directory); > - > -static int readFD(int fd, char **buf) { > - char *p; > - size_t size = 4096; > - int s, filesize = 0; > - > - *buf = calloc(4096, sizeof (char)); > - if (*buf == NULL) > - abort(); > - > - do { > - p = &(*buf)[filesize]; > - s = read(fd, p, 4096); > - if (s < 0) > - break; > - > - filesize += s; > - if (s == 0) > - break; > - > - size += s; > - *buf = realloc(*buf, size); > - if (*buf == NULL) > - abort(); > - } while (1); > - > - if (filesize == 0 && s < 0) { > - free(*buf); > - *buf = NULL; > - return -1; > - } > - > - return filesize; > +static int mkdirIfNone(char *directory); > + > +static int readFD(int fd, char **buf) > +{ > + char *p; > + size_t size = 4096; > + int s, filesize = 0; > + > + *buf = calloc(4096, sizeof(char)); > + if (*buf == NULL) > + abort(); > + > + do { > + p = &(*buf)[filesize]; > + s = read(fd, p, 4096); > + if (s < 0) > + break; > + > + filesize += s; > + if (s == 0) > + break; > + > + size += s; > + *buf = realloc(*buf, size); > + if (*buf == NULL) > + abort(); > + } while (1); > + > + if (filesize == 0 && s < 0) { > + free(*buf); > + *buf = NULL; > + return -1; > + } > + > + return filesize; > } > > int mountCommandWrapper(int mode, char *dev, char *where, char *fs, > - char *options, char **err) { > - int rc, child, status, pipefd[2]; > - char *opts = NULL, *device = NULL, *cmd = NULL; > - int programLogFD; > - > - if (mode == IMOUNT_MODE_MOUNT) { > - cmd = "/bin/mount"; > - } else if (mode == IMOUNT_MODE_UMOUNT) { > - cmd = "/bin/umount"; > - } else { > - return IMOUNT_ERR_MODE; > - } > - > - if (mode == IMOUNT_MODE_MOUNT) { > - if (mkdirChain(where)) > - return IMOUNT_ERR_ERRNO; > - > - if (strstr(fs, "nfs")) { > - if (options) { > - if (asprintf(&opts, "%s,nolock", options) == -1) { > - fprintf(stderr, "%s: %d: %s\n", __func__, > __LINE__, > - strerror(errno)); > - fflush(stderr); > - abort(); > - } > - } else { > - opts = strdup("nolock"); > - } > - > - device = strdup(dev); > - } else { > - if ((options && strstr(options, "bind") == NULL) && > - strncmp(dev, "LABEL=", 6) && strncmp(dev, "UUID=", 5) > && > - *dev != '/') { > - if (asprintf(&device, "/dev/%s", dev) == -1) { > - fprintf(stderr, "%s: %d: %s\n", __func__, > __LINE__, > - strerror(errno)); > - fflush(stderr); > - abort(); > - } > - } else { > - device = strdup(dev); > - } > - > - if (options) > - opts = strdup(options); > - } > - } > - > - programLogFD = open("/tmp/program.log", > - O_APPEND|O_CREAT|O_WRONLY, > S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); > - > - if (pipe(pipefd)) > - return IMOUNT_ERR_ERRNO; > - > - if (!(child = fork())) { > - int fd; > - > - close(pipefd[0]); > - > - /* Close stdin entirely, redirect stdout to /tmp/program.log, > and > - * redirect stderr to a pipe so we can put error messages > into > - * exceptions. We'll only use these messages should mount > also > - * return an error code. > - */ > - fd = open("/dev/tty5", O_RDONLY); > - close(STDIN_FILENO); > - dup2(fd, STDIN_FILENO); > - close(fd); > - > - close(STDOUT_FILENO); > - dup2(programLogFD, STDOUT_FILENO); > - > - dup2(pipefd[1], STDERR_FILENO); > - > - if (mode == IMOUNT_MODE_MOUNT) { > - if (opts) { > - fprintf(stdout, "Running... %s -n -t %s -o %s %s > %s\n", > - cmd, fs, opts, device, where); > - rc = execl(cmd, cmd, > - "-n", "-t", fs, "-o", opts, device, where, > NULL); > - exit(1); > - } else { > - fprintf(stdout, "Running... %s -n -t %s %s %s\n", > - cmd, fs, device, where); > - rc = execl(cmd, cmd, "-n", "-t", fs, device, where, > NULL); > - exit(1); > - } > - } else if (mode == IMOUNT_MODE_UMOUNT) { > - fprintf(stdout, "Running... %s %s\n", cmd, where); > - rc = execl(cmd, cmd, where, NULL); > - exit(1); > - } else { > - fprintf(stdout, "Running... Unknown imount mode: %d\n", > mode); > - exit(1); > - } > - } > - > - close(pipefd[1]); > - > - if (err != NULL) { > - if (*err != NULL) { > - rc = readFD(pipefd[0], err); > - rc = write(programLogFD, *err, 4096); > - } > - } > - > - close(pipefd[0]); > - waitpid(child, &status, 0); > - > - close(programLogFD); > - > - if (opts) { > - free(opts); > - } > - > - if (device) { > - free(device); > - } > - > - if (!WIFEXITED(status)) > - return IMOUNT_ERR_OTHER; > - else if ( (rc = WEXITSTATUS(status)) ) { > - /* Refer to 'man mount' for the meaning of the error codes. > */ > - switch (rc) { > - case 1: > - return IMOUNT_ERR_PERMISSIONS; > - case 2: > - return IMOUNT_ERR_SYSTEM; > - case 4: > - return IMOUNT_ERR_MOUNTINTERNAL; > - case 8: > - return IMOUNT_ERR_USERINTERRUPT; > - case 16: > - return IMOUNT_ERR_MTAB; > - case 32: > - return IMOUNT_ERR_MOUNTFAILURE; > - case 64: > - return IMOUNT_ERR_PARTIALSUCC; > - default: > - return IMOUNT_ERR_OTHER; > - } > - } > - > - return 0; > -} > + char *options, char **err) > +{ > + int rc, child, status, pipefd[2]; > + char *opts = NULL, *device = NULL, *cmd = NULL; > + int programLogFD; > + > + if (mode == IMOUNT_MODE_MOUNT) { > + cmd = "/bin/mount"; > + } else if (mode == IMOUNT_MODE_UMOUNT) { > + cmd = "/bin/umount"; > + } else { > + return IMOUNT_ERR_MODE; > + } > > -int doPwMount(char *dev, char *where, char *fs, char *options, char > **err) { > - return mountCommandWrapper(IMOUNT_MODE_MOUNT, > - dev, where, fs, options, err); > -} > + if (mode == IMOUNT_MODE_MOUNT) { > + if (mkdirChain(where)) > + return IMOUNT_ERR_ERRNO; > + > + if (strstr(fs, "nfs")) { > + if (options) { > + if (asprintf(&opts, "%s,nolock", options) == -1) { > + fprintf(stderr, "%s: %d: %s\n", > + __func__, __LINE__, > + strerror(errno)); > + fflush(stderr); > + abort(); > + } > + } else { > + opts = strdup("nolock"); > + } > + > + device = strdup(dev); > + } else { > + if ((options && strstr(options, "bind") == NULL) && > + strncmp(dev, "LABEL=", 6) > + && strncmp(dev, "UUID=", 5) && *dev != '/') { > + if (asprintf(&device, "/dev/%s", dev) == -1) { > + fprintf(stderr, "%s: %d: %s\n", > + __func__, __LINE__, > + strerror(errno)); > + fflush(stderr); > + abort(); > + } > + } else { > + device = strdup(dev); > + } > + > + if (options) > + opts = strdup(options); > + } > + } > > -int doPwUmount(char *where, char **err) { > - return mountCommandWrapper(IMOUNT_MODE_UMOUNT, > - NULL, where, NULL, NULL, err); > -} > + programLogFD = open("/tmp/program.log", > + O_APPEND | O_CREAT | O_WRONLY, > + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); > + > + if (pipe(pipefd)) > + return IMOUNT_ERR_ERRNO; > + > + if (!(child = fork())) { > + int fd; > + > + close(pipefd[0]); > + > + /* Close stdin entirely, redirect stdout to /tmp/program.log, and > + * redirect stderr to a pipe so we can put error messages into > + * exceptions. We'll only use these messages should mount also > + * return an error code. > + */ > + fd = open("/dev/tty5", O_RDONLY); > + close(STDIN_FILENO); > + dup2(fd, STDIN_FILENO); > + close(fd); > + > + close(STDOUT_FILENO); > + dup2(programLogFD, STDOUT_FILENO); > + > + dup2(pipefd[1], STDERR_FILENO); > + > + if (mode == IMOUNT_MODE_MOUNT) { > + if (opts) { > + fprintf(stdout, > + "Running... %s -n -t %s -o %s %s %s\n", > + cmd, fs, opts, device, where); > + rc = execl(cmd, cmd, "-n", "-t", fs, "-o", opts, > + device, where, NULL); > + exit(1); > + } else { > + fprintf(stdout, > + "Running... %s -n -t %s %s %s\n", cmd, > + fs, device, where); > + rc = execl(cmd, cmd, "-n", "-t", fs, device, > + where, NULL); > + exit(1); > + } > + } else if (mode == IMOUNT_MODE_UMOUNT) { > + fprintf(stdout, "Running... %s %s\n", cmd, where); > + rc = execl(cmd, cmd, where, NULL); > + exit(1); > + } else { > + fprintf(stdout, "Running... Unknown imount mode: %d\n", > + mode); > + exit(1); > + } > + } > + > + close(pipefd[1]); > > -int mkdirChain(char * origChain) { > - char * chain; > - char * chptr; > + if (err != NULL) { > + if (*err != NULL) { > + rc = readFD(pipefd[0], err); > + rc = write(programLogFD, *err, 4096); > + } > + } > + > + close(pipefd[0]); > + waitpid(child, &status, 0); > > - chain = alloca(strlen(origChain) + 1); > - strcpy(chain, origChain); > - chptr = chain; > + close(programLogFD); > > - while ((chptr = strchr(chptr, '/'))) { > - *chptr = '\0'; > - if (mkdirIfNone(chain)) { > - *chptr = '/'; > - return IMOUNT_ERR_ERRNO; > + if (opts) { > + free(opts); > } > > - *chptr = '/'; > - chptr++; > - } > + if (device) { > + free(device); > + } > > - if (mkdirIfNone(chain)) > - return IMOUNT_ERR_ERRNO; > + if (!WIFEXITED(status)) > + return IMOUNT_ERR_OTHER; > + else if ((rc = WEXITSTATUS(status))) { > + /* Refer to 'man mount' for the meaning of the error codes. */ > + switch (rc) { > + case 1: > + return IMOUNT_ERR_PERMISSIONS; > + case 2: > + return IMOUNT_ERR_SYSTEM; > + case 4: > + return IMOUNT_ERR_MOUNTINTERNAL; > + case 8: > + return IMOUNT_ERR_USERINTERRUPT; > + case 16: > + return IMOUNT_ERR_MTAB; > + case 32: > + return IMOUNT_ERR_MOUNTFAILURE; > + case 64: > + return IMOUNT_ERR_PARTIALSUCC; > + default: > + return IMOUNT_ERR_OTHER; > + } > + } > + > + return 0; > +} > + > +int doPwMount(char *dev, char *where, char *fs, char *options, char > **err) > +{ > + return mountCommandWrapper(IMOUNT_MODE_MOUNT, > + dev, where, fs, options, err); > +} > + > +int doPwUmount(char *where, char **err) > +{ > + return mountCommandWrapper(IMOUNT_MODE_UMOUNT, > + NULL, where, NULL, NULL, err); > +} > + > +int mkdirChain(char *origChain) > +{ > + char *chain; > + char *chptr; > + > + chain = alloca(strlen(origChain) + 1); > + strcpy(chain, origChain); > + chptr = chain; > + > + while ((chptr = strchr(chptr, '/'))) { > + *chptr = '\0'; > + if (mkdirIfNone(chain)) { > + *chptr = '/'; > + return IMOUNT_ERR_ERRNO; > + } > + > + *chptr = '/'; > + chptr++; > + } > > - return 0; > + if (mkdirIfNone(chain)) > + return IMOUNT_ERR_ERRNO; > + > + return 0; > } > > /* Returns true iff it is possible that the mount command that have > returned > @@ -256,37 +268,42 @@ int mkdirChain(char * origChain) { > * device, etc.) */ > int mountMightSucceedLater(int mountRc) > { > - int rc; > - switch (mountRc) { > - case IMOUNT_ERR_MOUNTFAILURE: > - rc = 1; > - break; > - default: > - rc = 0; > - } > - return rc; > + int rc; > + switch (mountRc) { > + case IMOUNT_ERR_MOUNTFAILURE: > + rc = 1; > + break; > + default: > + rc = 0; > + } > + return rc; > } > > -static int mkdirIfNone(char * directory) { > - int rc, mkerr; > - char * chptr; > +static int mkdirIfNone(char *directory) > +{ > + int rc, mkerr; > + char *chptr; > > - /* If the file exists it *better* be a directory -- I'm not going > to > - actually check or anything */ > - if (!access(directory, X_OK)) return 0; > + /* If the file exists it *better* be a directory -- I'm not going > to > + actually check or anything */ > + if (!access(directory, X_OK)) > + return 0; > > - /* if the path is '/' we get ENOFILE not found" from mkdir, > rather > - then EEXIST which is weird */ > - for (chptr = directory; *chptr; chptr++) > - if (*chptr != '/') break; > - if (!*chptr) return 0; > + /* if the path is '/' we get ENOFILE not found" from mkdir, rather > + then EEXIST which is weird */ > + for (chptr = directory; *chptr; chptr++) > + if (*chptr != '/') > + break; > + if (!*chptr) > + return 0; > > - rc = mkdir(directory, 0755); > - mkerr = errno; > + rc = mkdir(directory, 0755); > + mkerr = errno; > > - if (!rc || mkerr == EEXIST) return 0; > + if (!rc || mkerr == EEXIST) > + return 0; > > - return IMOUNT_ERR_ERRNO; > + return IMOUNT_ERR_ERRNO; > } > > /* vim:set sw=8 noet */ > diff --git a/isys/imount.h b/isys/imount.h > index 108f535..95b99ef 100644 > --- a/isys/imount.h > +++ b/isys/imount.h > @@ -42,7 +42,7 @@ > > int doPwMount(char *dev, char *where, char *fs, char *options, char > **err); > int doPwUmount(char *where, char **err); > -int mkdirChain(char * origChain); > +int mkdirChain(char *origChain); > int mountMightSucceedLater(int mountRc); > > #endif > diff --git a/isys/isofs.c b/isys/isofs.c > index 404283e..1579d42 100644 > --- a/isys/isofs.c > +++ b/isys/isofs.c > @@ -22,36 +22,37 @@ > #include <unistd.h> > > #define BLOCK_SIZE 2048 > - > -/* returns 1 if file is an ISO, 0 otherwise */ > -int fileIsIso(const char * file) { > - int blkNum; > - char magic[5]; > - int fd; > - > - fd = open(file, O_RDONLY); > - if (fd < 0) > - return 0; > - > - for (blkNum = 16; blkNum < 100; blkNum++) { > - if (lseek(fd, blkNum * BLOCK_SIZE + 1, SEEK_SET) < 0) { > - close(fd); > - return 0; > - } > > - if (read(fd, magic, sizeof(magic)) != sizeof(magic)) { > - close(fd); > - return 0; > - } > - > - if (!strncmp(magic, "CD001", 5)) { > - close(fd); > - return 1; > +/* returns 1 if file is an ISO, 0 otherwise */ > +int fileIsIso(const char *file) > +{ > + int blkNum; > + char magic[5]; > + int fd; > + > + fd = open(file, O_RDONLY); > + if (fd < 0) > + return 0; > + > + for (blkNum = 16; blkNum < 100; blkNum++) { > + if (lseek(fd, blkNum * BLOCK_SIZE + 1, SEEK_SET) < 0) { > + close(fd); > + return 0; > + } > + > + if (read(fd, magic, sizeof(magic)) != sizeof(magic)) { > + close(fd); > + return 0; > + } > + > + if (!strncmp(magic, "CD001", 5)) { > + close(fd); > + return 1; > + } > } > - } > > - close(fd); > - return 0; > + close(fd); > + return 0; > } > > /* vim:set sw=8 noet */ > diff --git a/isys/isys.c b/isys/isys.c > index 997f37e..64a3d83 100644 > --- a/isys/isys.c > +++ b/isys/isys.c > @@ -81,90 +81,95 @@ > #define CDROMEJECT 0x5309 > #endif > > -static PyObject * doMount(PyObject * s, PyObject * args); > -static PyObject * doUMount(PyObject * s, PyObject * args); > -static PyObject * doSwapon(PyObject * s, PyObject * args); > -static PyObject * doSwapoff(PyObject * s, PyObject * args); > -static PyObject * doLoSetup(PyObject * s, PyObject * args); > -static PyObject * doUnLoSetup(PyObject * s, PyObject * args); > -static PyObject * doLoChangeFd(PyObject * s, PyObject * args); > -static PyObject * doWipeRaidSuperblock(PyObject * s, PyObject * > args); > -static PyObject * doGetRaidChunkSize(PyObject * s, PyObject * args); > -static PyObject * doDevSpaceFree(PyObject * s, PyObject * args); > -static PyObject * doResetResolv(PyObject * s, PyObject * args); > -static PyObject * doLoadKeymap(PyObject * s, PyObject * args); > -static PyObject * doExt2Dirty(PyObject * s, PyObject * args); > -static PyObject * doExt2HasJournal(PyObject * s, PyObject * args); > -static PyObject * doEjectCdrom(PyObject * s, PyObject * args); > -static PyObject * doVtActivate(PyObject * s, PyObject * args); > -static PyObject * doisPseudoTTY(PyObject * s, PyObject * args); > -static PyObject * doisVioConsole(PyObject * s); > -static PyObject * doSync(PyObject * s, PyObject * args); > -static PyObject * doisIsoImage(PyObject * s, PyObject * args); > -static PyObject * printObject(PyObject * s, PyObject * args); > -static PyObject * py_bind_textdomain_codeset(PyObject * o, PyObject * > args); > -static PyObject * py_getDasdPorts(PyObject * s, PyObject * args); > -static PyObject * py_isUsableDasd(PyObject * s, PyObject * args); > -static PyObject * py_isLdlDasd(PyObject * s, PyObject * args); > -static PyObject * doProbeBiosDisks(PyObject * s, PyObject * args); > -static PyObject * doGetBiosDisk(PyObject * s, PyObject * args); > -static PyObject * doSegvHandler(PyObject *s, PyObject *args); > -static PyObject * doAuditDaemon(PyObject *s); > -static PyObject * doPrefixToNetmask(PyObject *s, PyObject *args); > -static PyObject * doGetBlkidData(PyObject * s, PyObject * args); > -static PyObject * doIsCapsLockEnabled(PyObject * s, PyObject * > args); > -static PyObject * doGetLinkStatus(PyObject * s, PyObject * args); > -static PyObject * doGetAnacondaVersion(PyObject * s, PyObject * > args); > +static PyObject *doMount(PyObject * s, PyObject * args); > +static PyObject *doUMount(PyObject * s, PyObject * args); > +static PyObject *doSwapon(PyObject * s, PyObject * args); > +static PyObject *doSwapoff(PyObject * s, PyObject * args); > +static PyObject *doLoSetup(PyObject * s, PyObject * args); > +static PyObject *doUnLoSetup(PyObject * s, PyObject * args); > +static PyObject *doLoChangeFd(PyObject * s, PyObject * args); > +static PyObject *doWipeRaidSuperblock(PyObject * s, PyObject * > args); > +static PyObject *doGetRaidChunkSize(PyObject * s, PyObject * args); > +static PyObject *doDevSpaceFree(PyObject * s, PyObject * args); > +static PyObject *doResetResolv(PyObject * s, PyObject * args); > +static PyObject *doLoadKeymap(PyObject * s, PyObject * args); > +static PyObject *doExt2Dirty(PyObject * s, PyObject * args); > +static PyObject *doExt2HasJournal(PyObject * s, PyObject * args); > +static PyObject *doEjectCdrom(PyObject * s, PyObject * args); > +static PyObject *doVtActivate(PyObject * s, PyObject * args); > +static PyObject *doisPseudoTTY(PyObject * s, PyObject * args); > +static PyObject *doisVioConsole(PyObject * s); > +static PyObject *doSync(PyObject * s, PyObject * args); > +static PyObject *doisIsoImage(PyObject * s, PyObject * args); > +static PyObject *printObject(PyObject * s, PyObject * args); > +static PyObject *py_bind_textdomain_codeset(PyObject * o, PyObject * > args); > +static PyObject *py_getDasdPorts(PyObject * s, PyObject * args); > +static PyObject *py_isUsableDasd(PyObject * s, PyObject * args); > +static PyObject *py_isLdlDasd(PyObject * s, PyObject * args); > +static PyObject *doProbeBiosDisks(PyObject * s, PyObject * args); > +static PyObject *doGetBiosDisk(PyObject * s, PyObject * args); > +static PyObject *doSegvHandler(PyObject * s, PyObject * args); > +static PyObject *doAuditDaemon(PyObject * s); > +static PyObject *doPrefixToNetmask(PyObject * s, PyObject * args); > +static PyObject *doGetBlkidData(PyObject * s, PyObject * args); > +static PyObject *doIsCapsLockEnabled(PyObject * s, PyObject * args); > +static PyObject *doGetLinkStatus(PyObject * s, PyObject * args); > +static PyObject *doGetAnacondaVersion(PyObject * s, PyObject * > args); > > static PyMethodDef isysModuleMethods[] = { > - { "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL > }, > - { "e2dirty", (PyCFunction) doExt2Dirty, METH_VARARGS, NULL }, > - { "e2hasjournal", (PyCFunction) doExt2HasJournal, METH_VARARGS, > NULL }, > - { "devSpaceFree", (PyCFunction) doDevSpaceFree, METH_VARARGS, > NULL }, > - { "wiperaidsb", (PyCFunction) doWipeRaidSuperblock, METH_VARARGS, > NULL }, > - { "getraidchunk", (PyCFunction) doGetRaidChunkSize, METH_VARARGS, > NULL }, > - { "lochangefd", (PyCFunction) doLoChangeFd, METH_VARARGS, NULL > }, > - { "losetup", (PyCFunction) doLoSetup, METH_VARARGS, NULL }, > - { "unlosetup", (PyCFunction) doUnLoSetup, METH_VARARGS, NULL }, > - { "mount", (PyCFunction) doMount, METH_VARARGS, NULL }, > - { "umount", (PyCFunction) doUMount, METH_VARARGS, NULL }, > - { "resetresolv", (PyCFunction) doResetResolv, METH_VARARGS, NULL > }, > - { "swapon", (PyCFunction) doSwapon, METH_VARARGS, NULL }, > - { "swapoff", (PyCFunction) doSwapoff, METH_VARARGS, NULL }, > - { "loadKeymap", (PyCFunction) doLoadKeymap, METH_VARARGS, NULL > }, > - { "vtActivate", (PyCFunction) doVtActivate, METH_VARARGS, NULL}, > - { "isPseudoTTY", (PyCFunction) doisPseudoTTY, METH_VARARGS, > NULL}, > - { "isVioConsole", (PyCFunction) doisVioConsole, METH_NOARGS, > NULL}, > - { "sync", (PyCFunction) doSync, METH_VARARGS, NULL}, > - { "isisoimage", (PyCFunction) doisIsoImage, METH_VARARGS, NULL}, > - { "printObject", (PyCFunction) printObject, METH_VARARGS, NULL}, > - { "bind_textdomain_codeset", (PyCFunction) > py_bind_textdomain_codeset, METH_VARARGS, NULL}, > - { "getDasdPorts", (PyCFunction) py_getDasdPorts, METH_VARARGS, > NULL}, > - { "isUsableDasd", (PyCFunction) py_isUsableDasd, METH_VARARGS, > NULL}, > - { "isLdlDasd", (PyCFunction) py_isLdlDasd, METH_VARARGS, NULL}, > - { "biosDiskProbe", (PyCFunction) doProbeBiosDisks, > METH_VARARGS,NULL}, > - { "getbiosdisk",(PyCFunction) doGetBiosDisk, METH_VARARGS,NULL}, > - { "handleSegv", (PyCFunction) doSegvHandler, METH_VARARGS, NULL > }, > - { "auditdaemon", (PyCFunction) doAuditDaemon, METH_NOARGS, NULL > }, > - { "prefix2netmask", (PyCFunction) doPrefixToNetmask, > METH_VARARGS, NULL }, > - { "getblkid", (PyCFunction) doGetBlkidData, METH_VARARGS, NULL > }, > - { "isCapsLockEnabled", (PyCFunction) doIsCapsLockEnabled, > METH_VARARGS, NULL }, > - { "getLinkStatus", (PyCFunction) doGetLinkStatus, METH_VARARGS, > NULL }, > - { "getAnacondaVersion", (PyCFunction) doGetAnacondaVersion, > METH_VARARGS, NULL }, > - { NULL, NULL, 0, NULL } > -} ; > - > -static PyObject * doUnLoSetup(PyObject * s, PyObject * args) { > - int loopfd; > - > - if (!PyArg_ParseTuple(args, "i", &loopfd)) return NULL; > - if (ioctl(loopfd, LOOP_CLR_FD, 0)) { > - PyErr_SetFromErrno(PyExc_SystemError); > - return NULL; > - } > + {"ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL}, > + {"e2dirty", (PyCFunction) doExt2Dirty, METH_VARARGS, NULL}, > + {"e2hasjournal", (PyCFunction) doExt2HasJournal, METH_VARARGS, > NULL}, > + {"devSpaceFree", (PyCFunction) doDevSpaceFree, METH_VARARGS, NULL}, > + {"wiperaidsb", (PyCFunction) doWipeRaidSuperblock, METH_VARARGS, > NULL}, > + {"getraidchunk", (PyCFunction) doGetRaidChunkSize, METH_VARARGS, > NULL}, > + {"lochangefd", (PyCFunction) doLoChangeFd, METH_VARARGS, NULL}, > + {"losetup", (PyCFunction) doLoSetup, METH_VARARGS, NULL}, > + {"unlosetup", (PyCFunction) doUnLoSetup, METH_VARARGS, NULL}, > + {"mount", (PyCFunction) doMount, METH_VARARGS, NULL}, > + {"umount", (PyCFunction) doUMount, METH_VARARGS, NULL}, > + {"resetresolv", (PyCFunction) doResetResolv, METH_VARARGS, NULL}, > + {"swapon", (PyCFunction) doSwapon, METH_VARARGS, NULL}, > + {"swapoff", (PyCFunction) doSwapoff, METH_VARARGS, NULL}, > + {"loadKeymap", (PyCFunction) doLoadKeymap, METH_VARARGS, NULL}, > + {"vtActivate", (PyCFunction) doVtActivate, METH_VARARGS, NULL}, > + {"isPseudoTTY", (PyCFunction) doisPseudoTTY, METH_VARARGS, NULL}, > + {"isVioConsole", (PyCFunction) doisVioConsole, METH_NOARGS, NULL}, > + {"sync", (PyCFunction) doSync, METH_VARARGS, NULL}, > + {"isisoimage", (PyCFunction) doisIsoImage, METH_VARARGS, NULL}, > + {"printObject", (PyCFunction) printObject, METH_VARARGS, NULL}, > + {"bind_textdomain_codeset", (PyCFunction) > py_bind_textdomain_codeset, > + METH_VARARGS, NULL}, > + {"getDasdPorts", (PyCFunction) py_getDasdPorts, METH_VARARGS, > NULL}, > + {"isUsableDasd", (PyCFunction) py_isUsableDasd, METH_VARARGS, > NULL}, > + {"isLdlDasd", (PyCFunction) py_isLdlDasd, METH_VARARGS, NULL}, > + {"biosDiskProbe", (PyCFunction) doProbeBiosDisks, METH_VARARGS, > NULL}, > + {"getbiosdisk", (PyCFunction) doGetBiosDisk, METH_VARARGS, NULL}, > + {"handleSegv", (PyCFunction) doSegvHandler, METH_VARARGS, NULL}, > + {"auditdaemon", (PyCFunction) doAuditDaemon, METH_NOARGS, NULL}, > + {"prefix2netmask", (PyCFunction) doPrefixToNetmask, METH_VARARGS, > NULL}, > + {"getblkid", (PyCFunction) doGetBlkidData, METH_VARARGS, NULL}, > + {"isCapsLockEnabled", (PyCFunction) doIsCapsLockEnabled, > METH_VARARGS, > + NULL}, > + {"getLinkStatus", (PyCFunction) doGetLinkStatus, METH_VARARGS, > NULL}, > + {"getAnacondaVersion", (PyCFunction) doGetAnacondaVersion, > METH_VARARGS, > + NULL}, > + {NULL, NULL, 0, NULL} > +}; > + > +static PyObject *doUnLoSetup(PyObject * s, PyObject * args) > +{ > + int loopfd; > + > + if (!PyArg_ParseTuple(args, "i", &loopfd)) > + return NULL; > + if (ioctl(loopfd, LOOP_CLR_FD, 0)) { > + PyErr_SetFromErrno(PyExc_S > > [Message truncated] _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list