summaryrefslogtreecommitdiff
path: root/src/sysv-generator
Commit message (Collapse)AuthorAgeFilesLines
* util-lib: split out allocation calls into alloc-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: split stat()/statfs()/stavfs() related calls into stat-util.[ch]Lennart Poettering2015-10-271-1/+2
|
* util-lib: split out hex/dec/oct encoding/decoding into its own fileLennart Poettering2015-10-271-0/+1
|
* util-lib: split out fd-related operations into fd-util.[ch]Lennart Poettering2015-10-251-0/+1
| | | | | There are more than enough to deserve their own .c file, hence move them over.
* util-lib: split our string related calls from util.[ch] into its own file ↵Lennart Poettering2015-10-241-8/+9
| | | | | | | | | | | | | | string-util.[ch] There are more than enough calls doing string manipulations to deserve its own files, hence do something about it. This patch also sorts the #include blocks of all files that needed to be updated, according to the sorting suggestions from CODING_STYLE. Since pretty much every file needs our string manipulation functions this effectively means that most files have sorted #include blocks now. Also touches a few unrelated include files.
* util: add safe_closedir() similar to safe_fclose()Lennart Poettering2015-09-221-2/+1
|
* sysv-generator: follow symlinks in /etc/rc.d/init.dLukas Nykryn2015-09-111-1/+1
| | | | | | | | | Some java packages puts a symlink to init.d and its content is pointing to latest java installation (because you can have multiple javas on you machine). On rhel-based distributions you can use alternatives --initscript instread of symlink, but this is not usable for other distributions.
* sysv-generator: fix coding-styleDavid Herrmann2015-07-011-13/+11
| | | | | | | | | Fix weird coding-style: - proper white-space - no if (func() >= 0) bail-outs - fix braces - avoid 'r' for anything but errno - init _cleanup_ variables unconditionally, even if not needed
* sysv-generator: escape names when translating from sysv nameFelipe Sateler2015-06-291-10/+12
| | | | | | While the LSB suggests only [A-Za-z0-9], that doesn't prevent admins from doing the wrong thing. Lets not generate invalid names in that case.
* sysv-generator: detect invalid provided unit namesFelipe Sateler2015-06-291-2/+8
| | | | Do not assume that a non-service unit type is a target.
* core: rename SystemdRunningAs to ManagerRunningAsLennart Poettering2015-05-111-1/+1
| | | | | | It's primarily just a property of the Manager object after all, and we try to refer to PID 1 as "manager" instead of "systemd", hence let's to stick to this here too.
* core,network: major per-object logging reworkLennart Poettering2015-05-111-20/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes log_unit_info() (and friends) to take a real Unit* object insted of just a unit name as parameter. The call will now prefix all logged messages with the unit name, thus allowing the unit name to be dropped from the various passed romat strings, simplifying invocations drastically, and unifying log output across messages. Also, UNIT= vs. USER_UNIT= is now derived from the Manager object attached to the Unit object, instead of getpid(). This has the benefit of correcting the field for --test runs. Also contains a couple of other logging improvements: - Drops a couple of strerror() invocations in favour of using %m. - Not only .mount units now warn if a symlinks exist for the mount point already, .automount units do that too, now. - A few invocations of log_struct() that didn't actually pass any additional structured data have been replaced by simpler invocations of log_unit_info() and friends. - For structured data a new LOG_UNIT_MESSAGE() macro has been added, that works like LOG_MESSAGE() but prefixes the message with the unit name. Similar, there's now LOG_LINK_MESSAGE() and LOG_NETDEV_MESSAGE(). - For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(), LOG_NETDEV_INTERFACE() macros have been added that generate the necessary per object fields. The old log_unit_struct() call has been removed in favour of these new macros used in raw log_struct() invocations. In addition to removing one more function call this allows generated structured log messages that contain two object fields, as necessary for example for network interfaces that are joined into another network interface, and whose messages shall be indexed by both. - The LOG_ERRNO() macro has been removed, in favour of log_struct_errno(). The latter has the benefit of ensuring that %m in format strings is properly resolved to the specified error number. - A number of logging messages have been converted to use log_unit_info() instead of log_info() - The client code in sysv-generator no longer #includes core code from src/core/. - log_unit_full_errno() has been removed, log_unit_full() instead takes an errno now, too. - log_unit_info(), log_link_info(), log_netdev_info() and friends, now avoid double evaluation of their parameters
* core: rework unit name validation and manipulation logicLennart Poettering2015-05-051-3/+5
| | | | | | | | | | | | | | | A variety of changes: - Make sure all our calls distuingish OOM from other errors if OOM is not the only error possible. - Be much stricter when parsing escaped paths, do not accept trailing or leading escaped slashes. - Change unit validation to take a bit mask for allowing plain names, instance names or template names or an combination thereof. - Refuse manipulating invalid unit name
* sysv-generator: avoid freeing uninitialized variableThomas Hindoe Paaboel Andersen2015-04-261-1/+1
| | | | Would happen if lookup_paths_init returns an error.
* sysv-generator: free memory allocated for service stubsZbigniew Jędrzejewski-Szmek2015-04-121-21/+31
|
* sysv-generator: always log on oomZbigniew Jędrzejewski-Szmek2015-04-121-27/+17
| | | | | | | | | | This code appears to follow the following convention: - all errors are logged at point of origin - oom errors abort execution, non-oom errors are logged but execution continues. Make sure all ooms result in a log message, and remove warning which could not be reached. Downgrade non-fatal errors to warnings.
* sysv-generator: split out two nested blocks into functionsZbigniew Jędrzejewski-Szmek2015-04-121-110/+110
| | | | | No functional change intended. Just splitting this out to make it easier to edit in the future.
* sysv-generator: free LookupPaths also on errorZbigniew Jędrzejewski-Szmek2015-04-121-3/+1
| | | | Followup for 7a03974a6f.
* sysv-generator: fix mem leaksThomas Hindoe Paaboel Andersen2015-04-111-1/+5
|
* sysv-generator: initialize LookupPaths just onceZbigniew Jędrzejewski-Szmek2015-03-141-7/+7
| | | | | | | | With debugging on, sysv-generator would print the full set of lookup paths for *every* sysv script. While at it, pass LookupPaths as a pointer in sysv-generator, and constify it everywhere.
* remove unused includesThomas Hindoe Paaboel Andersen2015-02-231-4/+0
| | | | | | This patch removes includes that are not used. The removals were found with include-what-you-use which checks if any of the symbols from a header is in use.
* sysv-generator: fix wrong "Overwriting existing symlink" warningsMartin Pitt2015-02-191-1/+1
| | | | | | | | Fix result testing of is_symlink() to ignore negative results, which happen if the file name does not exist at all. In this case we do not want a warning and unlink the non-existing link. https://bugs.debian.org/778700
* everywhere: remove configurability of sysv runlevel to target mappingLennart Poettering2015-02-181-5/+5
| | | | | | | | | | | | | | | With this change runlevel 2, 3, 4 are mapped to multi-user.target for good, and 5 to graphical.target. This was already the previous mapping but is now no longer reconfigurable, but hard-coded into the core. This should generally simplify things, but also fix one bug: the sysv-generator previously generated symlinks to runlevel[2-5].target units, which possibly weren't picked up if these aliases were otherwise only referenced by the real names "multi-user.target" and "graphical.target". We keep compat aliases "runlevel[2345].target" arround for cases where this target name is explicitly requested.
* sysv-generator: Skip init scripts for existing native servicesMartin Pitt2015-02-111-1/+7
| | | | | | | | | This avoids taking the SysV init script enablement state into account if we have native units. Otherwise systemctl disable on native unit would not be respected in the presence of an enabled SysV script. Also, there's no need to do all the parsing and creation of service files if we already have a native systemd unit for the processed SysV init script.
* sysv-generator: no need to check for identical symlinks source and target twiceLennart Poettering2015-01-281-8/+4
| | | | http://lists.freedesktop.org/archives/systemd-devel/2015-January/027594.html
* sysv-generator: Re-fix .sh suffix handlingMartin Pitt2015-01-281-5/+3
| | | | | | | | | Commit 4e48855534 caused the .sh suffix to be stripped from the original "filename", which caused the generated units to call the wrong init.d script. Only use the .sh stripped file name for comparing with Provides:, not for generating the Exec*= lines. Spotted by sysv-generator-test.
* sysv-generator: there's really no need to invoke fstatat() multiple times on ↵Lennart Poettering2015-01-281-8/+6
| | | | | | | the same sysv script It's sufficient to check once if something is a regular file, hence, let's do that.
* sysv-generator: use is_symlink() utility call where appropriateLennart Poettering2015-01-271-3/+2
|
* sysv-generator: minor simplificationsLennart Poettering2015-01-271-11/+9
|
* sysv-generator: only allow regular files in enumerate_sysv()Cristian Rodríguez2015-01-221-2/+4
| | | | | Otherwise, if the directory contains other directories we fail at fopen in load_sysv() with EISDIR.
* sysv-generator: Replace Provides: symlinks with real unitsMartin Pitt2015-01-211-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | Since commit b7e7184 the SysV generator creates symlinks for all "Provides:" in the LSB header. However, this is too greedy; there are cases where the creation of a unit .service file fails because of an already existing symlink with the same name: - Backup files such as /etc/init.d/foo.bak still have "Provides: foo", and thus get a foo.service -> foo.bak.service link. foo.bak would not be enabled in rcN.d/, but we (deliberately) create units for all executables in init.d/ so that a manual "systemctl start" works. If foo.bak is processed before, the symlink already exists. - init.d/bar has "Provides: foo", while there also is a real init.d/foo. The former would create a link foo.service -> bar.service, while the latter would fail to create the real foo.service. If we encounter an existing symlink, just remove it before writing a real unit. Note that two init.d scripts "foo" and "bar" which both provide the same name "common" already work. The first processed init script wins and creates the "common.service" symlink, and the second just fails to create the symlink again. Thus create an additional test case for this to ensure that it keeps working sensibly. https://bugs.debian.org/775404
* sysv-generator: Handle .sh suffixes when translating Provides:Martin Pitt2015-01-211-1/+14
| | | | | | | | | | | | | | | When deciding whether the provided name equals the file name in sysv_translate_facility(), also consider them equal if the file name has a ".sh" suffix. This was uncovered by commit b7e7184 which then created a symlink "<name>.service" to itself for ".sh" suffixed init.d scripts. For additional robustness, refuse to create symlinks to itself in add_alias(). Add test case which reproduces the bug. https://bugs.debian.org/775889
* sysv-generator: always use fstatat() if we canLennart Poettering2015-01-141-10/+14
|
* sysv-generator: fix memory leak on failureLennart Poettering2015-01-141-5/+9
| | | | | This fixes a memory leak introduced by 1ed0c19f81fd13cdf283c6def0168ce122a853a9
* sysv-generator: initialize units before use to ensure correct orderingMichael Biebl2015-01-071-4/+4
| | | | | | | | | | | | | | The original loop called fix_order() on each service immediately after loading it, but fix_order() would reference other units which were not loaded yet. This resulted in bogus and unnecessary orderings based on the static start priorities. Therefore call load_sysv() for every init script when traversing them in enumerate_sysv(). This ensures that all units are loaded when fix_order() is called. Bug-Debian: https://bugs.debian.org/771118
* sysv-generator: handle Provides: for non-virtual facility namesMichael Biebl2015-01-071-1/+24
| | | | | | | | | | | | | | | | | | | | The list of provided facility names as specified via Provides: in the LSB header was originally implemented by adding those facilities to the Names= property via unit_add_name(). In commit 95ed3294c632f5606327149f10cef1eb34422862 the internal SysV support was replaced by a generator and support for parsing the Names= option had been removed from the unit file parsing in v186. As a result, Provides: for non-virtual facility was dropped when introducing the sysv-generator. Since quite a few SysV init scripts still use that functionality (at least in distros like Debian which have a large body of SysV init scripts), add back support by making those facility names available via symlinks to the unit filename to ensure correct orderings between SysV init scripts which use those facility names. Bug-Debian: https://bugs.debian.org/774335
* sysv-generator: properly add Makefile symlinkLennart Poettering2014-12-191-1/+1
|
* util: rename ignore_file() to hidden_file()Lennart Poettering2014-12-191-2/+2
| | | | | hidden_file() is a bit more precise, since dot files usually shouldn't be ignored, but certainly be considered hidden.
* core: warn and ignore SysVStartPriority=Zbigniew Jędrzejewski-Szmek2014-11-301-3/+0
| | | | Option was being parsed but not used for anything.
* treewide: another round of simplificationsMichal Schmidt2014-11-281-4/+2
| | | | | Using the same scripts as in f647962d64e "treewide: yet more log_*_errno + return simplifications".
* treewide: use log_*_errno whenever %m is in the format stringMichal Schmidt2014-11-281-3/+3
| | | | | | | | | | | If the format string contains %m, clearly errno must have a meaningful value, so we might as well use log_*_errno to have ERRNO= logged. Using: find . -name '*.[ch]' | xargs sed -r -i -e \ 's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/' Plus some whitespace, linewrap, and indent adjustments.
* core: convert log_unit_*() to log_unit_*_errno()Michal Schmidt2014-11-281-1/+1
| | | | | | Using: find . -name '*.[ch]' | xargs sed -r -i -e \ 's/log_unit_(debug|info|notice|warning|error|emergency)\(([^"]+), "(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_unit_\1_errno(\2, \5, "\3%m"\4);/'
* sysv-generator: advertise the man pageZbigniew Jędrzejewski-Szmek2014-11-271-0/+1
|
* log: rearrange log function namingLennart Poettering2014-11-271-8/+8
| | | | | | | | | | - Rename log_meta() → log_internal(), to follow naming scheme of most other log functions that are usually invoked through macros, but never directly. - Rename log_info_object() to log_object_info(), simply because the object should be before any other parameters, to follow OO-style programming style.
* Remove repeated includesThomas Hindoe Paaboel Andersen2014-10-011-1/+0
| | | | | | In pty.c there was both an include of our pty.h and the system installed pty.h. The latter contains only two functions openpty and forkpty. We use neither so I assume it was a typo and removed it. We still compile and pass all tests.
* sysv-generator: don't check first if hashmap contains the service nameThomas Hindoe Paaboel Andersen2014-09-171-3/+2
| | | | | | | | Just test if hashmap_get returns null. hashmap_contains does exactly same thing internally so this is slightly more efficient for the true case. Silences a coverity warning too. CID#1237648
* sysv-generator: fix resource leakAndreas Henriksson2014-09-161-1/+1
| | | | | | The "unit" string allocation is not freed on either error or success path. Found by coverity. Fixes: CID#1237755
* hashmap: introduce hash_ops to make struct Hashmap smallerMichal Schmidt2014-09-151-5/+3
| | | | | | | | | It is redundant to store 'hash' and 'compare' function pointers in struct Hashmap separately. The functions always comprise a pair. Store a single pointer to struct hash_ops instead. systemd keeps hundreds of hashmaps, so this saves a little bit of memory.
* Properly report invalid quoted stringsZbigniew Jędrzejewski-Szmek2014-07-311-0/+9
| | | | | | | | $ systemd-analyze verify trailing-g.service [./trailing-g.service:2] Trailing garbage, ignoring. trailing-g.service lacks ExecStart setting. Refusing. Error: org.freedesktop.systemd1.LoadFailed: Unit trailing-g.service failed to load: Invalid argument. Failed to create trailing-g.service/start: Invalid argument
* Reject invalid quoted stringsZbigniew Jędrzejewski-Szmek2014-07-311-6/+6
| | | | | | | | | | | | | | | | | | | | | | String which ended in an unfinished quote were accepted, potentially with bad memory accesses. Reject anything which ends in a unfished quote, or contains non-whitespace characters right after the closing quote. _FOREACH_WORD now returns the invalid character in *state. But this return value is not checked anywhere yet. Also, make 'word' and 'state' variables const pointers, and rename 'w' to 'word' in various places. Things are easier to read if the same name is used consistently. mbiebl_> am I correct that something like this doesn't work mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-passwd "Unlock EncFS"' mbiebl_> systemd seems to strip of the quotes mbiebl_> systemctl status shows mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-password Unlock EncFS $RootDir $MountPoint mbiebl_> which is pretty weird