summaryrefslogtreecommitdiff
path: root/utils
Commit message (Collapse)AuthorAgeFilesLines
* utils: don't ignore open() return valueDaniel Golle2021-08-311-1/+6
| | | | | | | | In case active console cannot be opened, return NULL early instead of trying to read from errornous file descriptor. Coverity CID: 1490087 Argument cannot be negative Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* utils: make sure read() string is 0 terminatedDaniel Golle2021-08-241-0/+1
| | | | | | Coverity CID: 1490062 String not null terminated Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* inittab: detect active console from kernel if no console= specifiedMathew McBride2021-03-072-0/+23
| | | | | | | | | | The default serial console can be set in the device tree using the linux,stdout-path parameter (or equivalent from ACPI). This is important for universal booting (EFI/EBBR) on ARM platforms where the default console can be different (e.g ttyS0 vs ttyAMA0). Signed-off-by: Mathew McBride <matt@traverse.com.au>
* utils: fix C style in header fileDaniel Golle2021-03-071-1/+1
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* procd: check strchr() result before using itJustinas Grauslis2019-07-131-1/+4
| | | | | | | | | | | | Subtracting some address from NULL does not necessary results in negative value. It's lower level dependent. In our case (IPQ4019 + Yocto + meta-openwrt) subtracting token address from NULL strchr() return value results in large positive number which causes out-of-boundary memory access and eventually a segfault. Signed-off-by: Justinas Grauslis <justinas@8devices.com>
* procd: Remove redundant errno variable in several printf functions.Rosen Penev2018-01-021-2/+2
| | | | | | %m, aka strerror(errno) is already used. No need to repeat it. Saves 280 bytes. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* procd: Replace strerror(errno) with %m.Rosen Penev2018-01-021-2/+2
| | | | | | Saves 1496 bytes from compiled size under glibc. No functional difference. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* procd: uClibc O_PATH backwards compatibility fixesHans Dedecker2016-08-121-0/+4
| | | | Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* _GNU_SOURCE should be defined for building vs uClibcAlexey Brodkin2016-05-231-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In uClibc-ng O_PATH and O_DIRECTORY are only defined if _GNU_SOURCE is defined. So explicitly define _GNU_SOURCE in sources that use O_PATH and O_DIRECTORY. Without that extra definition that's what happens when building procd. utils/utils.c: ------------------------->8---------------------- .../openwrt/build_dir/target-arc_arc700_uClibc-1.0.14/procd-2016-05-19/utils/utils.c: In function 'patch_fd': .../openwrt/build_dir/target-arc_arc700_uClibc-1.0.14/procd-2016-05-19/utils/utils.c:168:22: error: 'O_PATH' undeclared (first use in this function) dfd = open("/dev", O_PATH|O_DIRECTORY); ^ .../openwrt/build_dir/target-arc_arc700_uClibc-1.0.14/procd-2016-05-19/utils/utils.c:168:22: note: each undeclared identifier is reported only once for each function it appears in .../openwrt/build_dir/target-arc_arc700_uClibc-1.0.14/procd-2016-05-19/utils/utils.c:168:29: error: 'O_DIRECTORY' undeclared (first use in this function) dfd = open("/dev", O_PATH|O_DIRECTORY); ^ CMakeFiles/init.dir/build.make:182: recipe for target 'CMakeFiles/init.dir/utils/utils.c.o' failed ------------------------->8---------------------- inittab.c: ------------------------->8---------------------- .../openwrt/build_dir/target-arc_arc700_uClibc-1.0.14/procd-2016-05-19/inittab.c: In function 'dev_exist': .../openwrt/build_dir/target-arc_arc700_uClibc-1.0.14/procd-2016-05-19/inittab.c:72:21: error: 'O_PATH' undeclared (first use in this function) dfd = open("/dev", O_PATH|O_DIRECTORY); ^ .../git/openwrt/build_dir/target-arc_arc700_uClibc-1.0.14/procd-2016-05-19/inittab.c:72:21: note: each undeclared identifier is reported only once for each function it appears in .../git/openwrt/build_dir/target-arc_arc700_uClibc-1.0.14/procd-2016-05-19/inittab.c:72:28: error: 'O_DIRECTORY' undeclared (first use in this function) dfd = open("/dev", O_PATH|O_DIRECTORY); ^ CMakeFiles/procd.dir/build.make:134: recipe for target 'CMakeFiles/procd.dir/inittab.c.o' failed make[6]: *** [CMakeFiles/procd.dir/inittab.c.o] Error 1 ------------------------->8---------------------- Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com> Cc: Waldemar Brodkorb <wbx@openadk.org> Cc: John Crispin <john@phrozen.org> Cc: Jo-Philipp Wich <jo@mein.io>
* utils: use O_PATH when opening /devJo-Philipp Wich2016-05-171-1/+1
| | | | | | | Use the O_PATH and O_DIRECTORY flags when opening the "/dev" path for the subsequent openat() call to ensure that it is indeed a directory. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* utils: add patch_fd() and patch_stdio() helpersJo-Philipp Wich2016-05-162-0/+57
| | | | | | | | | | | | | | | | | | | | Introduce two new helper functions to deal with stdio redirecation in a uniform, reliable manner: The patch_fd() function will attempt to redirect the given fd number to the specified file, using the supplied flags for the open() syscall. When the device is NULL, "/dev/null" is asumed, when the device is a relative path, openat() is used to open it relative to the "/dev" directory. When the device cannot be openend, a fallback to "/dev/null" is attempted. The patch_stdio() function is essentially a wrapper around patch_fd(), providing an easy interface to redirect stdin, stdout and stderr to the same given device. Both function return 0 on success and -1 on error. The errno variable will be set accordingly. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* utils.c: remove an unnecessary includeFelix Fietkau2016-03-051-1/+0
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* check for empty parameters in askfirstZefir Kurtisi2015-03-181-1/+6
| | | | Signed-off-by: Zefir Kurtisi <zefir.kurtisi@neratec.com>
* get_cmdline_val: search for entire name, not just suffixSteven Barth2014-11-051-27/+18
| | | | | | also fix writing of 0-byte to buffer Signed-off-by: Steven Barth <steven@midlink.org>
* Honour tty field in /etc/inittabMichel Stam2014-11-041-26/+2
| | | | | | | | | | | | | | The problem was caused by procd not opening /dev/tty* (whichever was specified for the ID field /etc/inittab), causing /proc/PID/fd to point to /dev/console instead. This is a rework of e63051d9, which did not initialise the console pointer and did not check the tty pointer in askconsole. askfirst was not completely fixed as it expected the console parameter on the commandline, which is no longer necessary because procd opens the console prior to fork()-ing. Signed-off-by: Michel Stam <m.stam@fugro.nl>
* Revert "Honour tty field in /etc/inittab"Steven Barth2014-11-011-2/+26
| | | | | | | This reverts commit e63051d9843ddbafb1fabfd97d60e853bdeac129. This unbreaks the initial console on UML and possibly other platforms. Signed-off-by: Steven Barth <cyrus@openwrt.org>
* Fix regression in command line parsingSteven Barth2014-10-312-3/+5
| | | | | | 79872ea6 reduced the command line buffer breaking various platforms. Signed-off-by: Steven Barth <steven@midlink.org>
* minor fixes to michels patchesJohn Crispin2014-10-121-4/+4
| | | | Signed-off-by: John Crispin <blogic@openwrt.org>
* Honour tty field in /etc/inittabMichel Stam2014-10-121-26/+2
| | | | | | | | The problem was caused by procd not opening /dev/tty* (whichever was specified for the ID field /etc/inittab), causing /proc/PID/fd to point to /dev/console instead. Signed-off-by: Michel Stam <m.stam@fugro.nl>
* Use one generic routine to access /proc/cmdlineMichel Stam2014-10-122-0/+43
| | | | Signed-off-by: Michel Stam <m.stam@fugro.nl>
* make ue of the md5.c inside libuboxJohn Crispin2013-11-192-277/+0
| | | | Signed-off-by: John Crispin <blogic@openwrt.org>
* debloat and reorganize codeJohn Crispin2013-11-155-0/+514
split app into procd and init binaries remove log support, this is an external service now Signed-off-by: John Crispin <blogic@openwrt.org>