aboutsummaryrefslogtreecommitdiff
path: root/src/librc/librc.c
AgeCommit message (Collapse)Author
2023-10-19librc.c: fix potential infinite loop in recusive_mkdirAnna (navi) Figueiredo Gomes
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-10-19librc: disallow running --user without XDG_RUNTIME_DIR setAnna (navi) Figueiredo Gomes
since openrc-pam now sets XDG_RUNTIME_DIR in case it's unset, we can expect it to exist. Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-10-19openrc-run: in user mode, change to homedir instead of /Anna (navi) Figueiredo Gomes
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-10-19librc: introduce recursive_mkdir()Anna (navi) Figueiredo Gomes
creates all the directories in a give path. only the last directory in the path return -1 to EEXIST. any other error is always returned. Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-10-19librc: disallow user scripts as rootAnna (navi) Figueiredo Gomes
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-10-19librc: add paths to errorx mkdir callsAnna (navi) Figueiredo Gomes
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-10-19openrc: rework pathing functionsAnna (navi) Figueiredo Gomes
this simplifies the allocation of path string. also fixes some memory leaks from the ealier commit also changes the log path for users to XDG_CACHE_HOME, default ~/.cache/openrc Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-10-19librc: Move sysconf dir to ~/.config/openrc/...Anna (navi) Figueiredo Gomes
Also add ~/.local/share/openrc for data files (like logs) This is done to help avoid name conflictions for anything else that might create/user files in .config/ Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-10-19librc: Use getpwuid instead of ${HOME} to get user's home directory.Anna (navi) Figueiredo Gomes
Using ${HOME} works when the user runs any librc program from the shell, but trying to invoke them from pam or similar, the variable is not set. Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-10-19openrc: Add support for user services.Anna (navi) Figueiredo Gomes
Modifies many functions where filesystem paths were hardcoded. In non-user-services mode, they still are. In user-services mode, they are allocated, since XDG_ dirs are to be set via environment variables. Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-10-19librc: skeleton of user services supportAnna (navi) Figueiredo Gomes
Those functions allocates and set up the environment for user services. Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-04-19Rename attribute macros to namespaced RC_*Sam James
This conflicts with linux-headers which uses __unused for some padding members on ppc64le at least. Closes: https://github.com/OpenRC/openrc/issues/622
2023-01-29librc: missing includes from IWYUSam James
2023-01-25librc: fix 'init' memory leakSam James
From scan-build w/ clang-16.0.0_pre20230107: ``` ../src/librc/librc.c:759:14: warning: Potential leak of memory pointed to by 'init' [unix.Malloc] return false; ^~~~~ ```
2022-05-08librc: fix resource leaksWilliam Hubbs
2022-05-08librc: fix potential use-after-freeSam James
Both 'pkg' and 'local' are referenced within list, so we can't free them yet. Signed-off-by: Sam James <sam@gentoo.org>
2022-05-08librc: fix double-freeSam James
'services' is still referenced by the list which gets returned. We can't free it. Thanks to GCC 11's -fanalyzer. Signed-off-by: Sam James <sam@gentoo.org>
2022-05-08librc: fix mismatched allocsSam James
Signed-off-by: Sam James <sam@gentoo.org>
2022-05-08librc: fix memory leak in rc_services_in_runlevel_stackedSam James
Seen on running rc-status. ``` ================================================================= ==14636==ERROR: LeakSanitizer: detected memory leaks Indirect leak of 72 byte(s) in 3 object(s) allocated from: #0 0x7f443412dcb7 in __interceptor_malloc /usr/src/debug/sys-devel/gcc-11.2.1_p20220312/gcc-11-20220312/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x7f443400c727 in xmalloc ../src/includes/helpers.h:64 #2 0x7f443400d1f4 in rc_stringlist_add ../src/librc/librc-stringlist.c:32 #3 0x7f4433fecc34 in get_runlevel_chain ../src/librc/librc.c:390 #4 0x7f4433fedc00 in rc_runlevel_stacks ../src/librc/librc.c:519 #5 0x7f4433ff1d8e in rc_services_in_runlevel_stacked ../src/librc/librc.c:976 #6 0x55be0e8f9517 in main ../src/rc/rc-status.c:407 #7 0x7f44334736cf in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 ``` Signed-off-by: Sam James <sam@gentoo.org>
2021-12-21code style: remove space after unary "not" operatorMatt Whitlock
There are no semantic changes in this commit. Suggested-by: Mike Frysinger <vapier@gentoo.org> See: https://github.com/OpenRC/openrc/pull/435#pullrequestreview-727035394
2021-12-20use HEAD in git URIs to point to the default branchMike Frysinger
This makes the URIs shorter and dynamic: whatever the default branch the repo uses will be used.
2021-12-20drop unused copyright variablesMike Frysinger
The existing copyright notices in the file headers cover these vars.
2021-08-13librc: fix rc_runlevel_exists return for empty stringWilliam Hubbs
This function should return false if the runlevel is an empty string. X-Gentoo-Bug: 803536 X-Gentoo-Bug-URL: https://bugs.gentoo.org/803536 Closes: https://github.com/OpenRC/openrc/pull/431
2019-07-24Fix build with ClangMartin Wilke
This fixes #313.
2019-02-26remove hidden-visibility.hWilliam Hubbs
I am removing this on the advice of a member of the Gentoo toolchain team. It was explained to me that this doesn't offer any significant benefits to OpenRC. If anyone ffeels differently, please open a pull request reverting this and adding an explanation of what it does and how to know which functions to mark hidden in the future. This fixes #301.
2019-02-12librc: fix realpath() return value checkEdan Bedrik
This fixes #226.
2018-12-27fix potential out-of-bounds readsphilhofer
readlink(3) does not nul-terminate the result it sticks into the supplied buffer. Consequently, the code rc = readlink(path, buf, sizeof(buf)); does not necessarily produce a C string. The code in rc_find_pid() produces some C strings this way and passes them to strlen() and strcmp(), which can lead to an out-of-bounds read. In this case, since the code already takes care to zero-initialize the buffers before passing them to readlink(3), only allow sizeof(buf)-1 bytes to be returned. (While fixing this issue, I fixed two other locations that used the same problematic pattern.) This fixes #270.
2018-08-06librc: fix EACCES errno false-positive crashZac Medico
Use errno != EACCES to fix false-positive for non-root users with grsecurity kernels. Fixes: 37e29442721a ("librc: Add check for crashed state") This fixes #237
2018-05-22librc: Add check for crashed stateWilliam Hubbs
In rc_service_state,, call rc_service_daemons_crashed to check for a crashed daemon if the service is started.
2018-05-22librc: Add crashed stateWilliam Hubbs
2017-10-26rc_service_value_set: remove the option if NULL is the valueWilliam Hubbs
This allows the equivalent of "unsetting" a value for a service.
2017-01-04Clean up warnings that can use the _unused macroBenda Xu
X-Gentoo-Bug: 604666 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=604666
2016-12-19librc: detect loops in stacked runlevels and abortDoug Freed
This fixes #109. X-Gentoo-Bug: 558700 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=558700
2016-07-31librc: fix Docker auto detectionWilliam Hubbs
The original auto detection of Docker containers assumed the presence of a container environment variable. However, Docker-1.12 does not implement this, and I'm not sure which versions of docker implemented it. The new test is for the presence of a file named .dockerenv in the root directory.
2016-01-19librc: handle rc_sys="prefix" even if we weren't built with a prefixDoug Freed
This probably isn't needed, but it mimics old behavior.
2016-01-19librc: fix handling the nothing special case for rc_sysDoug Freed
2016-01-19librc: move system detection code into rc_sys and use itDoug Freed
This fixes an issue where librc code was calling code that only existed in the rc binary. This reverts commits 8addd79 and 9f6e056 This fixes #75.
2015-12-21Convert OpenRC to a centralized copyright/license structureWilliam Hubbs
In the past, OpenRC was a hybrid of a centralized and file-scope license/copyright structure. I followed the instructions from the Software Freedom Law Center [1] to convert to a Centralized structure where possible, for easier future maintenance. [1] https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html
2015-12-02Add detection for rkt containersWilliam Hubbs
2015-12-02Add detection for docker containersWilliam Hubbs
2015-12-01librc: comsolidate rc_sys_v1 and rc_sys_v2 into rc_sysWilliam Hubbs
These functions were never meant to be used outside of OpenRC, and they were added when we thought we were going to do away with the automatic detection of subsystems. Since the autodetection is not going away, we can combine these functions into rc_sys.
2015-05-04librc: Fix crash if the service name is the same as the including runlevelJakob Drexel
If a service has the same name as the runlevel it is in, openrc will crash on changing to such runlevel. It goes in a recursive madness and eventually gets a SEGV while in snprintf (don't know why). This fixes two errors: 1. ls_dir stats files not with full path -> stat always returns != 0 2. ls_dir adds files to list if stat failed This fixes #53. X-Gentoo-Bug: 537304 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=537304
2015-05-01Add support for systemd-nspawn containersWilliam Hubbs
This adds support for running OpenRC in a container created by the systemd-nspawn utility. This fixes #52. X-Gentoo-Bug: 548058 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=548058
2014-10-23Bundle <sys/queue.h> from NetBSDAnthony G. Basile
We are bundling this to allow building on musl-based systems since musl does not include <sys/queue.h>.
2013-10-21librc: do not allow "." and ".." as runlevel namesWilliam Hubbs
The rc_runlevel_exists function was attempting to treat "." and ".." as valid runlevels; however, this should not be allowed. X-Gentoo-Bug: 488710 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=488710
2013-10-04librc: fix a read off-by-one bugNatanael Copa
We should first check if we are within bounds and then read rather than the opposite. This makes valgrind happy. Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2013-09-20Fix stacked runlevel supportAlexander V Vershilov
Patch was provided by Max Hacking <max.gentoo.bugzilla@hacking.co.uk> and slightly fixed by Alexander Vershilov <qnikst@gentoo.org> and William Hubbs <williamh@gentoo.org>. Fixes: 1). Rebase to newest OpenRC version. 2). Remove code style fixes. Port to currect code style. 3). Fix rc_runlevel_stack instead of introducing new function. 4). Make get_runlevel_chain a private function. X-Gentoo-Bug: 467368 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=467368
2013-04-09Fix autodetection of lxcNatanael Copa
The /proc/1/environ contains various \0 terminated strings. The current code will only work when the search string is in the first of those. To fix this we look for strings in entire buffer. Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2012-07-26Bring Back prefix supportWilliam Hubbs
We now have a team member who is interested in OpenRC on prefix, so I am bringing it back to the main tree.
2012-02-21Remove prefix supportWilliam Hubbs
I spoke with the prefix team sometime back and was told that they do not have an interest in using OpenRC on prefix systems.