On Fri, 31.10.14 16:01, Timofey Titovets (nefelim...@gmail.com) wrote: > > +void get_rootbdev(char *rootbdev) { > + FILE *file = fopen("/proc/self/mountinfo", "r"); > + char mnt_point[PATH_MAX]; > + char mnt_source[PATH_MAX]; > + char t[256]; // Trash > + while (file && strcmp(mnt_point, "/") && !feof(file)){ > + fscanf(file, "%s %s %s %s %s %s %s %s %s %s %s", > + t,t,t,t, > + mnt_point, t,t,t,t, > + mnt_source, t); > + } > + if(!strcmp(mnt_point, "/")) > + strncpy(rootbdev, &mnt_source[5], 3); > + fclose(file); > +} > +
Umm, the error handling is missing. We don't invoke functions from variable definitions. We do not allocate over-sized buffers on the stack. Either we do it with the right size or with dyanmic memory. We generally don't use strcmp() for simple equality checks, but streq(). We use _cleanup_xyz_ to automatically free resources. Please have a look at the CODING_STYLE document in the repository. In general, I wouldn't consult mountinfo for this at all. Instead stat() the root fs, then use udev_device_new_from_devnum() on the returned st_dev, and read the device symlinks from that. Lennart -- Lennart Poettering, Red Hat _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel