From: Zbigniew Jędrzejewski-Szmek Date: Tue, 3 Oct 2017 08:41:51 +0000 (+0200) Subject: build-sys: use #if Y instead of #ifdef Y everywhere X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=3344b839df8fe2dd2b4a4f470225e4c407cf2faa;p=elogind.git build-sys: use #if Y instead of #ifdef Y everywhere The advantage is that is the name is mispellt, cpp will warn us. $ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/" $ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;' $ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g' $ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g' + manual changes to meson.build squash! build-sys: use #if Y instead of #ifdef Y everywhere v2: - fix incorrect setting of HAVE_LIBIDN2 --- diff --git a/man/meson.build b/man/meson.build index 7eb68e524..d5e4e9089 100644 --- a/man/meson.build +++ b/man/meson.build @@ -53,7 +53,7 @@ foreach tuple : manpages mandirn = join_paths(get_option('mandir'), 'man' + section) - if condition == '' or conf.get(condition, false) + if condition == '' or conf.get(condition) == 1 p1 = custom_target( man, input : xml, diff --git a/meson.build b/meson.build index 7e0890404..31494a3d3 100644 --- a/meson.build +++ b/meson.build @@ -45,8 +45,8 @@ m4_defines = [] ##################################################################### rootprefixdir = get_option('rootprefix') +conf.set10('HAVE_SPLIT_USR', get_option('split-usr')) if get_option('split-usr') - conf.set('HAVE_SPLIT_USR', true) rootprefixdir = rootprefixdir != '' ? rootprefixdir : '/' else rootprefixdir = rootprefixdir != '' ? rootprefixdir : '/usr' @@ -55,11 +55,10 @@ endif #if 0 /// UNNEEDED by elogind # sysvinit_path = get_option('sysvinit-path') # sysvrcnd_path = get_option('sysvrcnd-path') -# if sysvinit_path != '' or sysvrcnd_path != '' -# conf.set('HAVE_SYSV_COMPAT', true, -# description : 'SysV init scripts and rcN.d links are supported') -# m4_defines += ['-DHAVE_SYSV_COMPAT'] -# endif +# have = sysvinit_path != '' or sysvrcnd_path != '' +# conf.set10('HAVE_SYSV_COMPAT', have, +# description : 'SysV init scripts and rcN.d links are supported') +# m4_defines += have ? ['-DHAVE_SYSV_COMPAT'] : [] #endif // 0 # join_paths ignore the preceding arguments if an absolute component is @@ -443,7 +442,7 @@ foreach decl : ['char16_t', # We get -1 if the size cannot be determined have = cc.sizeof(decl, prefix : decl_headers) > 0 - conf.set('HAVE_' + decl.underscorify().to_upper(), have) + conf.set10('HAVE_' + decl.underscorify().to_upper(), have) endforeach foreach decl : [['IFLA_INET6_ADDR_GEN_MODE', 'linux/if_link.h'], @@ -475,12 +474,8 @@ foreach decl : [['IFLA_INET6_ADDR_GEN_MODE', 'linux/if_link.h'], conf.set10('HAVE_' + decl[0], have) endforeach -skip = false foreach ident : ['secure_getenv', '__secure_getenv'] - if not skip and cc.has_function(ident) - conf.set('HAVE_' + ident.to_upper(), true) - skip = true - endif + conf.set10('HAVE_' + ident.to_upper(), cc.has_function(ident)) endforeach foreach ident : [ @@ -509,10 +504,11 @@ foreach ident : [ endforeach if cc.has_function('getrandom', prefix : '''#include ''') - conf.set('USE_SYS_RANDOM_H', true) + conf.set10('USE_SYS_RANDOM_H', true) conf.set10('HAVE_GETRANDOM', true) else have = cc.has_function('getrandom', prefix : '''#include ''') + conf.set10('USE_SYS_RANDOM_H', false) conf.set10('HAVE_GETRANDOM', have) endif @@ -607,12 +603,13 @@ endif foreach header : ['linux/btrfs.h', 'linux/memfd.h', 'linux/vm_sockets.h', + 'sys/auxv.h', 'valgrind/memcheck.h', 'valgrind/valgrind.h', ] - conf.set('HAVE_' + header.underscorify().to_upper(), - cc.has_header(header)) + conf.set10('HAVE_' + header.underscorify().to_upper(), + cc.has_header(header)) endforeach ############################################################ @@ -734,21 +731,25 @@ conf.set_quoted('GETTEXT_PACKAGE', meson.project_name()) #endif // 0 debug = get_option('debug') +enable_debug_hashmap = false +enable_debug_mmap_cache = false if debug != '' foreach name : debug.split(',') if name == 'hashmap' - conf.set('ENABLE_DEBUG_HASHMAP', true) + enable_debug_hashmap = true elif name == 'mmap-cache' - conf.set('ENABLE_DEBUG_MMAP_CACHE', true) #if 1 /// additional elogind debug mode elif name == 'elogind' conf.set('ENABLE_DEBUG_ELOGIND', true) #endif // 1 + enable_debug_mmap_cache = true else message('unknown debug option "@0@", ignoring'.format(name)) endif endforeach endif +conf.set10('ENABLE_DEBUG_HASHMAP', enable_debug_hashmap) +conf.set10('ENABLE_DEBUG_MMAP_CACHE', enable_debug_mmap_cache) ##################################################################### @@ -773,45 +774,45 @@ endif # libseccomp = dependency('libseccomp', # version : '>= 2.3.1', # required : want_seccomp == 'true') -# if libseccomp.found() -# conf.set('HAVE_SECCOMP', true) -# m4_defines += ['-DHAVE_SECCOMP'] -# endif +# have = libseccomp.found() # else +# have = false # libseccomp = [] # endif #else libseccomp = [] #endif // 0 +conf.set10('HAVE_SECCOMP', have) +m4_defines += have ? ['-DHAVE_SECCOMP'] : [] want_selinux = get_option('selinux') if want_selinux != 'false' libselinux = dependency('libselinux', version : '>= 2.1.9', required : want_selinux == 'true') - if libselinux.found() - conf.set('HAVE_SELINUX', true) - m4_defines += ['-DHAVE_SELINUX'] - endif + have = libselinux.found() else + have = false libselinux = [] endif +conf.set10('HAVE_SELINUX', have) +m4_defines += have ? ['-DHAVE_SELINUX'] : [] #if 0 /// UNNEEDED by elogind # want_apparmor = get_option('apparmor') # if want_apparmor != 'false' # libapparmor = dependency('libapparmor', # required : want_apparmor == 'true') -# if libapparmor.found() -# conf.set('HAVE_APPARMOR', true) -# m4_defines += ['-DHAVE_APPARMOR'] -# endif +# have = libapparmor.found() # else +# have = false # libapparmor = [] # endif #else libapparmor = [] #endif // 0 +conf.set10('HAVE_APPARMOR', have) +m4_defines += have ? ['-DHAVE_APPARMOR'] : [] smack_run_label = get_option('smack-run-label') if smack_run_label != '' @@ -823,7 +824,6 @@ want_polkit = get_option('polkit') install_polkit = false install_polkit_pkla = false if want_polkit != 'false' - conf.set('ENABLE_POLKIT', true) install_polkit = true libpolkit = dependency('polkit-gobject-1', @@ -833,44 +833,51 @@ if want_polkit != 'false' install_polkit_pkla = true endif endif +conf.set10('ENABLE_POLKIT', install_polkit) want_acl = get_option('acl') if want_acl != 'false' libacl = cc.find_library('acl', required : want_acl == 'true') - if libacl.found() - conf.set('HAVE_ACL', true) - m4_defines += ['-DHAVE_ACL'] - endif + have = libacl.found() else + have = false libacl = [] endif +conf.set10('HAVE_ACL', have) +m4_defines += have ? ['-DHAVE_ACL'] : [] want_audit = get_option('audit') if want_audit != 'false' libaudit = dependency('audit', required : want_audit == 'true') - conf.set('HAVE_AUDIT', libaudit.found()) + have = libaudit.found() else + have = false libaudit = [] endif +conf.set10('HAVE_AUDIT', have) #if 0 /// UNNEEDED by elogind # want_blkid = get_option('blkid') # if want_blkid != 'false' # libblkid = dependency('blkid', required : want_blkid == 'true') -# conf.set('HAVE_BLKID', libblkid.found()) +# have = libblkid.found() # else +# have = false # libblkid = [] # endif +# conf.set10('HAVE_BLKID', have) # # want_kmod = get_option('kmod') # if want_kmod != 'false' # libkmod = dependency('libkmod', # version : '>= 15', # required : want_kmod == 'true') -# conf.set('HAVE_KMOD', libkmod.found()) +# have = libkmod.found() # else +# have = false # libkmod = [] # endif +# conf.set10('HAVE_KMOD', have) #else libblkid = [] libkmod = [] @@ -880,14 +887,14 @@ want_pam = get_option('pam') if want_pam != 'false' libpam = cc.find_library('pam', required : want_pam == 'true') libpam_misc = cc.find_library('pam_misc', required : want_pam == 'true') - if libpam.found() and libpam_misc.found() - conf.set('HAVE_PAM', true) - m4_defines += ['-DHAVE_PAM'] - endif + have = libpam.found() and libpam_misc.found() else + have = false libpam = [] libpam_misc = [] endif +conf.set10('HAVE_PAM', have) +m4_defines += have ? ['-DHAVE_PAM'] : [] #if 0 /// UNNEEDED by elogind # want_microhttpd = get_option('microhttpd') @@ -895,36 +902,38 @@ endif # libmicrohttpd = dependency('libmicrohttpd', # version : '>= 0.9.33', # required : want_microhttpd == 'true') -# if libmicrohttpd.found() -# conf.set('HAVE_MICROHTTPD', true) -# m4_defines += ['-DHAVE_MICROHTTPD'] -# endif +# have = libmicrohttpd.found() # else +# have = false # libmicrohttpd = [] # endif +# conf.set10('HAVE_MICROHTTPD', have) +# m4_defines += have ? ['-DHAVE_MICROHTTPD'] : [] # # want_libcryptsetup = get_option('libcryptsetup') # if want_libcryptsetup != 'false' # libcryptsetup = dependency('libcryptsetup', # version : '>= 1.6.0', # required : want_libcryptsetup == 'true') -# conf.set('HAVE_LIBCRYPTSETUP', libcryptsetup.found()) +# have = libcryptsetup.found() # else +# have = false # libcryptsetup = [] # endif +# conf.set10('HAVE_LIBCRYPTSETUP', have) # # want_libcurl = get_option('libcurl') # if want_libcurl != 'false' # libcurl = dependency('libcurl', # version : '>= 7.32.0', # required : want_libcurl == 'true') -# if libcurl.found() -# conf.set('HAVE_LIBCURL', true) -# m4_defines += ['-DHAVE_LIBCURL'] -# endif +# have = libcurl.found() # else +# have = false # libcurl = [] # endif +# conf.set10('HAVE_LIBCURL', have) +# m4_defines += have ? ['-DHAVE_LIBCURL'] : [] # # want_libidn = get_option('libidn') # want_libidn2 = get_option('libidn2') @@ -935,123 +944,137 @@ endif # if want_libidn != 'false' and want_libidn2 != 'true' # libidn = dependency('libidn', # required : want_libidn == 'true') -# if libidn.found() -# conf.set('HAVE_LIBIDN', true) -# m4_defines += ['-DHAVE_LIBIDN'] -# endif +# have = libidn.found() # else +# have = false # libidn = [] # endif -# if not conf.get('HAVE_LIBIDN', false) and want_libidn2 != 'false' +# conf.set10('HAVE_LIBIDN', have) +# m4_defines += have ? ['-DHAVE_LIBIDN'] : [] +# if not have and want_libidn2 != 'false' # # libidn is used for both libidn and libidn2 objects # libidn = dependency('libidn2', # required : want_libidn2 == 'true') -# if libidn.found() -# conf.set('HAVE_LIBIDN2', true) -# m4_defines += ['-DHAVE_LIBIDN2'] -# endif +# have = libidn.found() +# else +# have = false # endif +# conf.set10('HAVE_LIBIDN2', have) +# m4_defines += have ? ['-DHAVE_LIBIDN2'] : [] # # want_libiptc = get_option('libiptc') # if want_libiptc != 'false' # libiptc = dependency('libiptc', # required : want_libiptc == 'true') -# if libiptc.found() -# conf.set('HAVE_LIBIPTC', true) -# m4_defines += ['-DHAVE_LIBIPTC'] -# endif +# have = libiptc.found() # else +# have = false # libiptc = [] # endif +# conf.set10('HAVE_LIBIPTC', have) +# m4_defines += have ? ['-DHAVE_LIBIPTC'] : [] # # want_qrencode = get_option('qrencode') # if want_qrencode != 'false' # libqrencode = dependency('libqrencode', # required : want_qrencode == 'true') -# conf.set('HAVE_QRENCODE', libqrencode.found()) +# have = libqrencode.found() # else +# have = false # libqrencode = [] # endif +# conf.set10('HAVE_QRENCODE', have) # # want_gcrypt = get_option('gcrypt') # if want_gcrypt != 'false' # libgcrypt = cc.find_library('gcrypt', required : want_gcrypt == 'true') # libgpg_error = cc.find_library('gpg-error', required : want_gcrypt == 'true') -# -# have_deps = libgcrypt.found() and libgpg_error.found() -# conf.set('HAVE_GCRYPT', have_deps) -# if not have_deps -# # link to neither of the libs if one is not found -# libgcrypt = [] -# libgpg_error = [] -# endif +# have = libgcrypt.found() and libgpg_error.found() # else +# have = false +# endif +# if not have +# # link to neither of the libs if one is not found # libgcrypt = [] # libgpg_error = [] # endif +# conf.set10('HAVE_GCRYPT', have) # # want_gnutls = get_option('gnutls') # if want_gnutls != 'false' # libgnutls = dependency('gnutls', # version : '>= 3.1.4', # required : want_gnutls == 'true') -# conf.set('HAVE_GNUTLS', libgnutls.found()) +# have = libgnutls.found() # else +# have = false # libgnutls = [] # endif +# conf.set10('HAVE_GNUTLS', have) # # want_elfutils = get_option('elfutils') # if want_elfutils != 'false' # libdw = dependency('libdw', # required : want_elfutils == 'true') -# conf.set('HAVE_ELFUTILS', libdw.found()) +# have = libdw.found() # else +# have = false # libdw = [] # endif +# conf.set10('HAVE_ELFUTILS', have) # # want_zlib = get_option('zlib') # if want_zlib != 'false' # libz = dependency('zlib', # required : want_zlib == 'true') -# conf.set('HAVE_ZLIB', libz.found()) +# have = libz.found() # else +# have = false # libz = [] # endif +# conf.set10('HAVE_ZLIB', have) # # want_bzip2 = get_option('bzip2') # if want_bzip2 != 'false' # libbzip2 = cc.find_library('bz2', # required : want_bzip2 == 'true') -# conf.set('HAVE_BZIP2', libbzip2.found()) +# have = libbzip2.found() # else +# have = false # libbzip2 = [] # endif +# conf.set10('HAVE_BZIP2', have) # # want_xz = get_option('xz') # if want_xz != 'false' # libxz = dependency('liblzma', # required : want_xz == 'true') -# conf.set('HAVE_XZ', libxz.found()) +# have = libxz.found() # else +# have = false # libxz = [] # endif +# conf.set10('HAVE_XZ', have) # # want_lz4 = get_option('lz4') # if want_lz4 != 'false' # liblz4 = dependency('liblz4', # required : want_lz4 == 'true') -# conf.set('HAVE_LZ4', liblz4.found()) +# have = liblz4.found() # else +# have = false # liblz4 = [] # endif +# conf.set10('HAVE_LZ4', have) # # want_xkbcommon = get_option('xkbcommon') # if want_xkbcommon != 'false' # libxkbcommon = dependency('xkbcommon', # version : '>= 0.3.0', # required : want_xkbcommon == 'true') -# conf.set('HAVE_XKBCOMMON', libxkbcommon.found()) +# have = libxkbcommon.found() # else +# have = false # libxkbcommon = [] # endif #else @@ -1071,6 +1094,7 @@ libxz = [] liblz4 = [] libxkbcommon = [] #endif // 0 +conf.set10('HAVE_XKBCOMMON', have) want_glib = get_option('glib') if want_glib != 'false' @@ -1083,26 +1107,29 @@ if want_glib != 'false' libgio = dependency('gio-2.0', required : want_glib == 'true') have = libglib.found() and libgobject.found() and libgio.found() - conf.set('HAVE_GLIB', have) else + have = false libglib = [] libgobject = [] libgio = [] endif +conf.set10('HAVE_GLIB', have) want_dbus = get_option('dbus') if want_dbus != 'false' libdbus = dependency('dbus-1', version : '>= 1.3.2', required : want_dbus == 'true') - conf.set('HAVE_DBUS', libdbus.found()) + have = libdbus.found() else + have = false libdbus = [] endif +conf.set10('HAVE_DBUS', have) #if 0 /// UNNEEDED by elogind # default_dnssec = get_option('default-dnssec') -# if default_dnssec != 'no' and not conf.get('HAVE_GCRYPT', false) +# if default_dnssec != 'no' and conf.get('HAVE_GCRYPT') == 0 # message('default-dnssec cannot be set to yes or allow-downgrade when gcrypt is disabled. Setting default-dnssec to no.') # default_dnssec = 'no' # endif @@ -1112,21 +1139,23 @@ endif # # want_importd = get_option('importd') # if want_importd != 'false' -# have_deps = (conf.get('HAVE_LIBCURL', false) and -# conf.get('HAVE_ZLIB', false) and -# conf.get('HAVE_BZIP2', false) and -# conf.get('HAVE_XZ', false) and -# conf.get('HAVE_GCRYPT', false)) -# conf.set('ENABLE_IMPORTD', have_deps) -# if want_importd == 'true' and not have_deps +# have = (conf.get('HAVE_LIBCURL') == 1 and +# conf.get('HAVE_ZLIB') == 1 and +# conf.get('HAVE_BZIP2') == 1 and +# conf.get('HAVE_XZ') == 1 and +# conf.get('HAVE_GCRYPT') == 1) +# if want_importd == 'true' and not have # error('importd support was requested, but dependencies are not available') # endif +# else +# have = false # endif +# conf.set10('ENABLE_IMPORTD', have) # # want_remote = get_option('remote') # if want_remote != 'false' -# have_deps = [conf.get('HAVE_MICROHTTPD', false), -# conf.get('HAVE_LIBCURL', false)] +# have_deps = [conf.get('HAVE_MICROHTTPD') == 1, +# conf.get('HAVE_LIBCURL') == 1] # # sd-j-remote requires µhttpd, and sd-j-upload requires libcurl, so # # it's possible to build one without the other. Complain only if # # support was explictly requested. The auxiliary files like sysusers @@ -1134,9 +1163,12 @@ endif # if want_remote == 'true' and not (have_deps[0] and have_deps[1]) # error('remote support was requested, but dependencies are not available') # endif -# conf.set('ENABLE_REMOTE', have_deps[0] or have_deps[1]) +# have = have_deps[0] or have_deps[1] +# else +# have = false # endif #endif // 0 +conf.set10('ENABLE_REMOTE', have) foreach pair : [['utmp', 'HAVE_UTMP'], #if 0 /// UNNEEDED by elogind @@ -1175,10 +1207,9 @@ foreach pair : [['utmp', 'HAVE_UTMP'], #endif // 0 ] - if get_option(pair[0]) - conf.set(pair[1], true) - m4_defines += ['-D' + pair[1]] - endif + have = get_option(pair[0]) + conf.set10(pair[1], have) + m4_defines += have ? ['-D' + pair[1]] : [] endforeach want_tests = get_option('tests') @@ -1210,12 +1241,15 @@ conf.set10('SYSTEMD_SLOW_TESTS_DEFAULT', get_option('slow-tests')) # gnu_efi_arch = '' # endif # -# conf.set('ENABLE_EFI', true) +# have = true # conf.set_quoted('EFI_MACHINE_TYPE_NAME', EFI_MACHINE_TYPE_NAME) # # conf.set('SD_TPM_PCR', get_option('tpm-pcrindex').to_int()) +# else +# have = false # endif #endif // 0 +conf.set10('ENABLE_EFI', have) ##################################################################### @@ -1365,20 +1399,20 @@ subdir('src/test') # only static linking apart from libdl, to make sure that the # module is linked to all libraries that it uses. +test_dlopen = executable( + 'test-dlopen', + test_dlopen_c, + include_directories : includes, + link_with : [libbasic], + dependencies : [libdl]) + #if 0 /// UNNEEDED by elogind -# test_dlopen = executable( -# 'test-dlopen', -# test_dlopen_c, -# include_directories : includes, -# link_with : [libbasic], -# dependencies : [libdl]) -# # foreach tuple : [['myhostname', 'HAVE_MYHOSTNAME'], # ['systemd', 'ENABLE_NSS_SYSTEMD'], # ['mymachines', 'ENABLE_MACHINED'], # ['resolve', 'ENABLE_RESOLVED']] # -# condition = tuple[1] == '' or conf.get(tuple[1], false) +# condition = tuple[1] == '' or conf.get(tuple[1]) == 1 # if condition # module = tuple[0] # @@ -1508,7 +1542,7 @@ subdir('src/test') # install : true, # install_dir : systemgeneratordir) # -# if conf.get('ENABLE_ENVIRONMENT_D', false) +# if conf.get('ENABLE_ENVIRONMENT_D') == 1 # executable('30-systemd-environment-d-generator', # 'src/environment-d-generator/environment-d-generator.c', # include_directories : includes, @@ -1522,7 +1556,7 @@ subdir('src/test') # join_paths(environmentdir, '99-environment.conf')) # endif # -# if conf.get('ENABLE_HIBERNATE', false) +# if conf.get('ENABLE_HIBERNATE') == 1 # executable('systemd-hibernate-resume-generator', # 'src/hibernate-resume/hibernate-resume-generator.c', # include_directories : includes, @@ -1540,7 +1574,7 @@ subdir('src/test') # install_dir : rootlibexecdir) # endif # -# if conf.get('HAVE_BLKID', false) +# if conf.get('HAVE_BLKID') == 1 # executable('systemd-gpt-auto-generator', # 'src/gpt-auto-generator/gpt-auto-generator.c', # 'src/basic/blkid-util.h', @@ -1561,7 +1595,7 @@ subdir('src/test') # public_programs += [exe] # endif # -# if conf.get('ENABLE_RESOLVED', false) +# if conf.get('ENABLE_RESOLVED') == 1 # executable('systemd-resolved', # systemd_resolved_sources, # gcrypt_util_sources, @@ -1591,7 +1625,7 @@ subdir('src/test') # public_programs += [exe] # endif # -# if conf.get('ENABLE_LOGIND', false) +# if conf.get('ENABLE_LOGIND') == 1 # executable('systemd-logind', # systemd_logind_sources, # include_directories : includes, @@ -1624,7 +1658,7 @@ subdir('src/test') # install_dir : rootbindir) # public_programs += [exe] # -# if conf.get('HAVE_PAM', false) +# if conf.get('HAVE_PAM') == 1 # version_script_arg = join_paths(meson.current_source_dir(), pam_systemd_sym) # pam_systemd = shared_library( # 'pam_systemd', @@ -1682,7 +1716,7 @@ exe = executable('elogind-inhibit', install_dir : rootbindir) public_programs += [exe] -if conf.get('HAVE_PAM', false) +if conf.get('HAVE_PAM') == 1 version_script_arg = join_paths(meson.current_source_dir(), pam_elogind_sym) pam_elogind = shared_library( 'pam_elogind', @@ -1699,9 +1733,13 @@ if conf.get('HAVE_PAM', false) link_depends : pam_elogind_sym, install : true, install_dir : pamlibdir) + + test('dlopen-pam_elogind', + test_dlopen, + args : [pam_elogind.full_path()]) # path to dlopen must include a slash endif -#endif // 0 #if 0 /// UNNEEDED by elogind +# if conf.get('HAVE_PAM') == 1 # executable('systemd-user-sessions', # 'src/user-sessions/user-sessions.c', # include_directories : includes, @@ -1711,7 +1749,7 @@ endif # install_dir : rootlibexecdir) # endif # -# if conf.get('ENABLE_EFI', false) and conf.get('HAVE_BLKID', false) +# if conf.get('ENABLE_EFI') == 1 and conf.get('HAVE_BLKID') == 1 # exe = executable('bootctl', # 'src/boot/bootctl.c', # include_directories : includes, @@ -1743,7 +1781,7 @@ endif # install_dir : rootbindir) # public_programs += [exe] # -# if conf.get('ENABLE_BACKLIGHT', false) +# if conf.get('ENABLE_BACKLIGHT') == 1 # executable('systemd-backlight', # 'src/backlight/backlight.c', # include_directories : includes, @@ -1753,7 +1791,7 @@ endif # install_dir : rootlibexecdir) # endif # -# if conf.get('ENABLE_RFKILL', false) +# if conf.get('ENABLE_RFKILL') == 1 # executable('systemd-rfkill', # 'src/rfkill/rfkill.c', # include_directories : includes, @@ -1771,7 +1809,7 @@ endif # install : true, # install_dir : systemgeneratordir) # -# if conf.get('HAVE_LIBCRYPTSETUP', false) +# if conf.get('HAVE_LIBCRYPTSETUP') == 1 # executable('systemd-cryptsetup', # 'src/cryptsetup/cryptsetup.c', # include_directories : includes, @@ -1809,7 +1847,7 @@ endif # install_dir : systemgeneratordir) # endif # -# if conf.get('HAVE_SYSV_COMPAT', false) +# if conf.get('HAVE_SYSV_COMPAT') == 1 # executable('systemd-sysv-generator', # 'src/sysv-generator/sysv-generator.c', # include_directories : includes, @@ -1827,7 +1865,7 @@ endif # install_dir : systemgeneratordir) # endif # -# if conf.get('ENABLE_HOSTNAMED', false) +# if conf.get('ENABLE_HOSTNAMED') == 1 # executable('systemd-hostnamed', # 'src/hostname/hostnamed.c', # include_directories : includes, @@ -1845,8 +1883,8 @@ endif # public_programs += [exe] # endif # -# if conf.get('ENABLE_LOCALED', false) -# if conf.get('HAVE_XKBCOMMON', false) +# if conf.get('ENABLE_LOCALED') == 1 +# if conf.get('HAVE_XKBCOMMON') == 1 # # logind will load libxkbcommon.so dynamically on its own # deps = [libdl] # else @@ -1871,7 +1909,7 @@ endif # public_programs += [exe] # endif # -# if conf.get('ENABLE_TIMEDATED', false) +# if conf.get('ENABLE_TIMEDATED') == 1 # executable('systemd-timedated', # 'src/timedate/timedated.c', # include_directories : includes, @@ -1889,7 +1927,7 @@ endif # public_programs += [exe] # endif # -# if conf.get('ENABLE_TIMESYNCD', false) +# if conf.get('ENABLE_TIMESYNCD') == 1 # executable('systemd-timesyncd', # systemd_timesyncd_sources, # include_directories : includes, @@ -1901,7 +1939,7 @@ endif # install_dir : rootlibexecdir) # endif # -# if conf.get('ENABLE_MACHINED', false) +# if conf.get('ENABLE_MACHINED') == 1 # executable('systemd-machined', # systemd_machined_sources, # include_directories : includes, @@ -1924,7 +1962,7 @@ endif # public_programs += [exe] # endif # -# if conf.get('ENABLE_IMPORTD', false) +# if conf.get('ENABLE_IMPORTD') == 1 # executable('systemd-importd', # systemd_importd_sources, # include_directories : includes, @@ -1973,7 +2011,7 @@ endif # public_programs += [systemd_pull, systemd_import, systemd_export] # endif # -# if conf.get('ENABLE_REMOTE', false) and conf.get('HAVE_LIBCURL', false) +# if conf.get('ENABLE_REMOTE') == 1 and conf.get('HAVE_LIBCURL') == 1 # exe = executable('systemd-journal-upload', # systemd_journal_upload_sources, # include_directories : includes, @@ -1989,7 +2027,7 @@ endif # public_programs += [exe] # endif # -# if conf.get('ENABLE_REMOTE', false) and conf.get('HAVE_MICROHTTPD', false) +# if conf.get('ENABLE_REMOTE') == 1 and conf.get('HAVE_MICROHTTPD') == 1 # s_j_remote = executable('systemd-journal-remote', # systemd_journal_remote_sources, # include_directories : includes, @@ -2018,7 +2056,7 @@ endif # public_programs += [s_j_remote, s_j_gatewayd] # endif # -# if conf.get('ENABLE_COREDUMP', false) +# if conf.get('ENABLE_COREDUMP') == 1 # executable('systemd-coredump', # systemd_coredump_sources, # include_directories : includes, @@ -2044,7 +2082,7 @@ endif # public_programs += [exe] # endif # -# if conf.get('ENABLE_BINFMT', false) +# if conf.get('ENABLE_BINFMT') == 1 # exe = executable('systemd-binfmt', # 'src/binfmt/binfmt.c', # include_directories : includes, @@ -2060,7 +2098,7 @@ endif # mkdir_p.format(join_paths(sysconfdir, 'binfmt.d'))) # endif # -# if conf.get('ENABLE_VCONSOLE', false) +# if conf.get('ENABLE_VCONSOLE') == 1 # executable('systemd-vconsole-setup', # 'src/vconsole/vconsole-setup.c', # include_directories : includes, @@ -2070,7 +2108,7 @@ endif # install_dir : rootlibexecdir) # endif # -# if conf.get('ENABLE_RANDOMSEED', false) +# if conf.get('ENABLE_RANDOMSEED') == 1 # executable('systemd-random-seed', # 'src/random-seed/random-seed.c', # include_directories : includes, @@ -2080,7 +2118,7 @@ endif # install_dir : rootlibexecdir) # endif # -# if conf.get('ENABLE_FIRSTBOOT', false) +# if conf.get('ENABLE_FIRSTBOOT') == 1 # executable('systemd-firstboot', # 'src/firstboot/firstboot.c', # include_directories : includes, @@ -2299,7 +2337,7 @@ executable('elogind-cgroups-agent', # install : true) # public_programs += [exe] # -# if conf.get('ENABLE_SYSUSERS', false) +# if conf.get('ENABLE_SYSUSERS') == 1 # exe = executable('systemd-sysusers', # 'src/sysusers/sysusers.c', # include_directories : includes, @@ -2310,7 +2348,7 @@ executable('elogind-cgroups-agent', # public_programs += [exe] # endif # -# if conf.get('ENABLE_TMPFILES', false) +# if conf.get('ENABLE_TMPFILES') == 1 # exe = executable('systemd-tmpfiles', # 'src/tmpfiles/tmpfiles.c', # include_directories : includes, @@ -2322,7 +2360,7 @@ executable('elogind-cgroups-agent', # public_programs += [exe] # endif # -# if conf.get('ENABLE_HWDB', false) +# if conf.get('ENABLE_HWDB') == 1 # exe = executable('systemd-hwdb', # 'src/hwdb/hwdb.c', # 'src/libsystemd/sd-hwdb/hwdb-internal.h', @@ -2334,7 +2372,7 @@ executable('elogind-cgroups-agent', # public_programs += [exe] # endif # -# if conf.get('ENABLE_QUOTACHECK', false) +# if conf.get('ENABLE_QUOTACHECK') == 1 # executable('systemd-quotacheck', # 'src/quotacheck/quotacheck.c', # include_directories : includes, @@ -2412,7 +2450,7 @@ executable('elogind-cgroups-agent', # install : true, # install_dir : rootlibexecdir) # -# if conf.get('HAVE_KMOD', false) +# if conf.get('HAVE_KMOD') == 1 # executable('systemd-modules-load', # 'src/modules-load/modules-load.c', # include_directories : includes, @@ -2444,7 +2482,7 @@ executable('elogind-cgroups-agent', # install : true) # public_programs += [exe] # -# if conf.get('ENABLE_NETWORKD', false) +# if conf.get('ENABLE_NETWORKD') == 1 # executable('systemd-networkd', # systemd_networkd_sources, # include_directories : includes, @@ -2495,7 +2533,7 @@ foreach tuple : tests type = '' endif - if condition == '' or conf.get(condition, false) + if condition == '' or conf.get(condition) == 1 exe = executable( name, sources, @@ -2734,7 +2772,7 @@ status = [ # LDFLAGS: ${OUR_LDFLAGS} ${LDFLAGS} #if 0 /// UNNEEDED by elogind -# if conf.get('ENABLE_EFI', false) +# if conf.get('ENABLE_EFI') == 1 # status += [ # 'efi arch: @0@'.format(efi_arch)] # @@ -2819,15 +2857,15 @@ foreach tuple : [ ['dbus'], ['glib'], #if 0 /// UNNEEDED by elogind -# ['nss-myhostname', conf.get('HAVE_MYHOSTNAME', false)], +# ['nss-myhostname', conf.get('HAVE_MYHOSTNAME') == 1], # ['hwdb'], # ['tpm'], #endif // 0 ['man pages', want_man], ['html pages', want_html], ['man page indices', want_man and have_lxml], - ['split /usr', conf.get('HAVE_SPLIT_USR', false)], #if 0 /// UNNEEDED by elogind +# ['split /usr', conf.get('HAVE_SPLIT_USR') == 1], # ['SysV compat'], #endif // 0 ['utmp'], @@ -2848,7 +2886,7 @@ foreach tuple : [ if cond == '' ident1 = 'HAVE_' + tuple[0].underscorify().to_upper() ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper() - cond = conf.get(ident1, false) or conf.get(ident2, false) + cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1 endif if cond found += [tuple[0]] diff --git a/shell-completion/bash/meson.build b/shell-completion/bash/meson.build index 684d1b5c2..de467101a 100644 --- a/shell-completion/bash/meson.build +++ b/shell-completion/bash/meson.build @@ -46,7 +46,7 @@ if bashcompletiondir != 'no' ] foreach item : items - if item[1] == '' or conf.get(item[1], false) + if item[1] == '' or conf.get(item[1]) == 1 install_data(item[0], install_dir : bashcompletiondir) endif diff --git a/shell-completion/zsh/meson.build b/shell-completion/zsh/meson.build index 4ddafe2a6..be30ebf0e 100644 --- a/shell-completion/zsh/meson.build +++ b/shell-completion/zsh/meson.build @@ -43,7 +43,7 @@ if zshcompletiondir != 'no' ] foreach item : items - if item[1] == '' or conf.get(item[1], false) + if item[1] == '' or conf.get(item[1]) == 1 install_data(item[0], install_dir : zshcompletiondir) endif diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 7d64c6a2b..630ae23a0 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -103,9 +103,12 @@ int cg_read_pid(FILE *f, pid_t *_pid) { return 1; } -int cg_read_event(const char *controller, const char *path, const char *event, - char **val) -{ +int cg_read_event( + const char *controller, + const char *path, + const char *event, + char **val) { + _cleanup_free_ char *events = NULL, *content = NULL; char *p, *line; int r; @@ -1034,7 +1037,7 @@ int cg_get_xattr(const char *controller, const char *path, const char *name, voi int cg_pid_get_path(const char *controller, pid_t pid, char **path) { _cleanup_fclose_ FILE *f = NULL; char line[LINE_MAX]; - const char *fs, *controller_str; + const char *fs, *controller_str = NULL; size_t cs = 0; int unified; @@ -2412,7 +2415,6 @@ int cg_mask_supported(CGroupMask *ret) { #if 0 /// UNNEEDED by elogind int cg_kernel_controllers(Set *controllers) { _cleanup_fclose_ FILE *f = NULL; - char buf[LINE_MAX]; int r; assert(controllers); @@ -2430,7 +2432,7 @@ int cg_kernel_controllers(Set *controllers) { } /* Ignore the header line */ - (void) fgets(buf, sizeof(buf), f); + (void) read_line(f, (size_t) -1, NULL); for (;;) { char *controller; diff --git a/src/basic/def.h b/src/basic/def.h index 1571f921b..377c0008c 100644 --- a/src/basic/def.h +++ b/src/basic/def.h @@ -55,7 +55,7 @@ #define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT #define SIGNALS_IGNORE SIGPIPE -#ifdef HAVE_SPLIT_USR +#if HAVE_SPLIT_USR #define KBD_KEYMAP_DIRS \ "/usr/share/keymaps/\0" \ "/usr/share/kbd/keymaps/\0" \ @@ -80,7 +80,7 @@ #define NOTIFY_FD_MAX 768 #define NOTIFY_BUFFER_MAX PIPE_BUF -#ifdef HAVE_SPLIT_USR +#if HAVE_SPLIT_USR # define _CONF_PATHS_SPLIT_USR(n) "/lib/" n "\0" #else # define _CONF_PATHS_SPLIT_USR(n) diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 3990d4dce..46b8b4a69 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -53,13 +53,17 @@ #define READ_FULL_BYTES_MAX (4U*1024U*1024U) -int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, struct timespec *ts) { +int write_string_stream_ts( + FILE *f, + const char *line, + WriteStringFileFlags flags, + struct timespec *ts) { assert(f); assert(line); fputs(line, f); - if (enforce_newline && !endswith(line, "\n")) + if (!(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n")) fputc('\n', f); if (ts) { @@ -69,10 +73,18 @@ int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, stru return -errno; } - return fflush_and_check(f); + if (flags & WRITE_STRING_FILE_SYNC) + return fflush_sync_and_check(f); + else + return fflush_and_check(f); } -static int write_string_file_atomic(const char *fn, const char *line, bool enforce_newline, bool do_fsync) { +static int write_string_file_atomic( + const char *fn, + const char *line, + WriteStringFileFlags flags, + struct timespec *ts) { + _cleanup_fclose_ FILE *f = NULL; _cleanup_free_ char *p = NULL; int r; @@ -86,22 +98,28 @@ static int write_string_file_atomic(const char *fn, const char *line, bool enfor (void) fchmod_umask(fileno(f), 0644); - r = write_string_stream(f, line, enforce_newline); - if (r >= 0 && do_fsync) - r = fflush_sync_and_check(f); + r = write_string_stream_ts(f, line, flags, ts); + if (r < 0) + goto fail; - if (r >= 0) { - if (rename(p, fn) < 0) - r = -errno; + if (rename(p, fn) < 0) { + r = -errno; + goto fail; } - if (r < 0) - (void) unlink(p); + return 0; +fail: + (void) unlink(p); return r; } -int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags flags, struct timespec *ts) { +int write_string_file_ts( + const char *fn, + const char *line, + WriteStringFileFlags flags, + struct timespec *ts) { + _cleanup_fclose_ FILE *f = NULL; int q, r; @@ -114,8 +132,7 @@ int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags if (flags & WRITE_STRING_FILE_ATOMIC) { assert(flags & WRITE_STRING_FILE_CREATE); - r = write_string_file_atomic(fn, line, !(flags & WRITE_STRING_FILE_AVOID_NEWLINE), - flags & WRITE_STRING_FILE_SYNC); + r = write_string_file_atomic(fn, line, flags, ts); if (r < 0) goto fail; @@ -148,16 +165,10 @@ int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags } } - r = write_string_stream_ts(f, line, !(flags & WRITE_STRING_FILE_AVOID_NEWLINE), ts); + r = write_string_stream_ts(f, line, flags, ts); if (r < 0) goto fail; - if (flags & WRITE_STRING_FILE_SYNC) { - r = fflush_sync_and_check(f); - if (r < 0) - return r; - } - return 0; fail: @@ -247,11 +258,11 @@ int read_full_stream(FILE *f, char **contents, size_t *size) { if (st.st_size > READ_FULL_BYTES_MAX) return -E2BIG; - /* Start with the right file size, but be prepared for - * files from /proc which generally report a file size - * of 0 */ + /* Start with the right file size, but be prepared for files from /proc which generally report a file + * size of 0. Note that we increase the size to read here by one, so that the first read attempt + * already makes us notice the EOF. */ if (st.st_size > 0) - n = st.st_size; + n = st.st_size + 1; } l = 0; @@ -264,12 +275,13 @@ int read_full_stream(FILE *f, char **contents, size_t *size) { return -ENOMEM; buf = t; + errno = 0; k = fread(buf + l, 1, n - l, f); if (k > 0) l += k; if (ferror(f)) - return -errno; + return errno > 0 ? -errno : -EIO; if (feof(f)) break; diff --git a/src/basic/fileio.h b/src/basic/fileio.h index 1160c5849..5b3d045e0 100644 --- a/src/basic/fileio.h +++ b/src/basic/fileio.h @@ -36,7 +36,7 @@ typedef enum { WRITE_STRING_FILE_SYNC = 1<<4, } WriteStringFileFlags; -int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, struct timespec *ts); +int write_string_stream_ts(FILE *f, const char *line, WriteStringFileFlags flags, struct timespec *ts); static inline int write_string_stream(FILE *f, const char *line, WriteStringFileFlags flags) { return write_string_stream_ts(f, line, flags, NULL); } diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 33467c379..9f18a42ff 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -46,6 +46,9 @@ #include "user-util.h" #include "util.h" +/// Additional includes needed by elogind +#include "process-util.h" + int unlink_noerrno(const char *path) { PROTECT_ERRNO; int r; diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index 51190b381..0a8f48d82 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -34,7 +34,7 @@ #include "strv.h" #include "util.h" -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP #include #include "list.h" #endif @@ -142,7 +142,7 @@ typedef uint8_t dib_raw_t; #define DIB_FREE UINT_MAX -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP struct hashmap_debug_info { LIST_FIELDS(struct hashmap_debug_info, debug_list); unsigned max_entries; /* high watermark of n_entries */ @@ -499,7 +499,7 @@ static void base_remove_entry(HashmapBase *h, unsigned idx) { dibs = dib_raw_ptr(h); assert(dibs[idx] != DIB_RAW_FREE); -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP h->debug.rem_count++; h->debug.last_rem_idx = idx; #endif @@ -578,7 +578,7 @@ static unsigned hashmap_iterate_in_insertion_order(OrderedHashmap *h, Iterator * assert(e->p.b.key == i->next_key); } -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP i->prev_idx = idx; #endif @@ -635,7 +635,7 @@ static unsigned hashmap_iterate_in_internal_order(HashmapBase *h, Iterator *i) { } idx = i->idx; -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP i->prev_idx = idx; #endif @@ -658,7 +658,7 @@ static unsigned hashmap_iterate_entry(HashmapBase *h, Iterator *i) { return IDX_NIL; } -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP if (i->idx == IDX_FIRST) { i->put_count = h->debug.put_count; i->rem_count = h->debug.rem_count; @@ -750,7 +750,7 @@ static struct HashmapBase *hashmap_base_new(const struct hash_ops *hash_ops, enu shared_hash_key_initialized= true; } -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP h->debug.func = func; h->debug.file = file; h->debug.line = line; @@ -807,7 +807,7 @@ static void hashmap_free_no_clear(HashmapBase *h) { assert(!h->has_indirect); assert(!h->n_direct_entries); -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP assert_se(pthread_mutex_lock(&hashmap_debug_list_mutex) == 0); LIST_REMOVE(debug_list, hashmap_debug_list, &h->debug); assert_se(pthread_mutex_unlock(&hashmap_debug_list_mutex) == 0); @@ -919,7 +919,7 @@ static bool hashmap_put_robin_hood(HashmapBase *h, unsigned idx, dib_raw_t raw_dib, *dibs; unsigned dib, distance; -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP h->debug.put_count++; #endif @@ -1012,7 +1012,7 @@ static int hashmap_base_put_boldly(HashmapBase *h, unsigned idx, assert_se(hashmap_put_robin_hood(h, idx, swap) == false); n_entries_inc(h); -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP h->debug.max_entries = MAX(h->debug.max_entries, n_entries(h)); #endif @@ -1240,7 +1240,7 @@ int hashmap_replace(Hashmap *h, const void *key, void *value) { idx = bucket_scan(h, hash, key); if (idx != IDX_NIL) { e = plain_bucket_at(h, idx); -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP /* Although the key is equal, the key pointer may have changed, * and this would break our assumption for iterating. So count * this operation as incompatible with iteration. */ diff --git a/src/basic/hashmap.h b/src/basic/hashmap.h index 6d1ae48b2..c1089652d 100644 --- a/src/basic/hashmap.h +++ b/src/basic/hashmap.h @@ -58,7 +58,7 @@ typedef struct Set Set; /* Stores just keys */ typedef struct { unsigned idx; /* index of an entry to be iterated next */ const void *next_key; /* expected value of that entry's key pointer */ -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP unsigned put_count; /* hashmap's put_count recorded at start of iteration */ unsigned rem_count; /* hashmap's rem_count in previous iteration */ unsigned prev_idx; /* idx in previous iteration */ @@ -89,7 +89,7 @@ typedef struct { (Hashmap*)(h), \ (void)0) -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP # define HASHMAP_DEBUG_PARAMS , const char *func, const char *file, int line # define HASHMAP_DEBUG_SRC_ARGS , __func__, __FILE__, __LINE__ # define HASHMAP_DEBUG_PASS_ARGS , func, file, line diff --git a/src/basic/memfd-util.c b/src/basic/memfd-util.c index e857c040d..ad80d5662 100644 --- a/src/basic/memfd-util.c +++ b/src/basic/memfd-util.c @@ -21,7 +21,7 @@ #include #include #include -#ifdef HAVE_LINUX_MEMFD_H +#if HAVE_LINUX_MEMFD_H #include #endif #include diff --git a/src/basic/meson.build b/src/basic/meson.build index 19e679fac..c1712f2db 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -295,6 +295,7 @@ basic_sources_plain = files(''' rm-rf.h selinux-util.c selinux-util.h + set.c set.h signal-util.c signal-util.h @@ -350,7 +351,7 @@ generate_gperfs = find_program('generate-gperfs.py') # output : 'af-list.txt', # command : [generate_af_list, cpp], # capture : true) -# +# # generate_arphrd_list = find_program('generate-arphrd-list.sh') # arphrd_list_txt = custom_target( # 'arphrd-list.txt', diff --git a/src/basic/missing.h b/src/basic/missing.h index f2f727822..7768b07e8 100644 --- a/src/basic/missing.h +++ b/src/basic/missing.h @@ -43,7 +43,7 @@ /// Additional includes needed by elogind #include "musl_missing.h" -#ifdef HAVE_AUDIT +#if HAVE_AUDIT #include #endif @@ -51,12 +51,12 @@ #include #endif -#ifdef HAVE_LINUX_BTRFS_H +#if HAVE_LINUX_BTRFS_H #include #endif #if 0 /// UNNEEDED by elogind -#ifdef HAVE_LINUX_VM_SOCKETS_H +#if HAVE_LINUX_VM_SOCKETS_H #include #else #define VMADDR_CID_ANY -1U @@ -210,7 +210,7 @@ struct sockaddr_vm { #endif #if 0 /// UNNEEDED by elogind (It can not support BTRFS at all) -#ifndef HAVE_LINUX_BTRFS_H +#if ! HAVE_LINUX_BTRFS_H struct btrfs_ioctl_vol_args { int64_t fd; char name[BTRFS_PATH_NAME_MAX + 1]; @@ -553,8 +553,8 @@ struct btrfs_ioctl_quota_ctl_args { #define MAX_HANDLE_SZ 128 #endif -#ifndef HAVE_SECURE_GETENV -# ifdef HAVE___SECURE_GETENV +#if ! HAVE_SECURE_GETENV +# if HAVE___SECURE_GETENV # define secure_getenv __secure_getenv # else # error "neither secure_getenv nor __secure_getenv are available" @@ -1117,7 +1117,7 @@ struct input_mask { #endif #endif // 0 -#ifndef HAVE_KEY_SERIAL_T +#if ! HAVE_KEY_SERIAL_T typedef int32_t key_serial_t; #endif @@ -1213,11 +1213,11 @@ typedef int32_t key_serial_t; #ifndef IF_OPER_UP #define IF_OPER_UP 6 -#ifndef HAVE_CHAR32_T +#if ! HAVE_CHAR32_T #define char32_t uint32_t #endif -#ifndef HAVE_CHAR16_T +#if ! HAVE_CHAR16_T #define char16_t uint16_t #endif @@ -1230,7 +1230,7 @@ typedef int32_t key_serial_t; #endif #if 0 /// UNNEEDED by elogind -#ifndef HAVE_STRUCT_ETHTOOL_LINK_SETTINGS +#if ! HAVE_STRUCT_ETHTOOL_LINK_SETTINGS #define ETHTOOL_GLINKSETTINGS 0x0000004c /* Get ethtool_link_settings */ #define ETHTOOL_SLINKSETTINGS 0x0000004d /* Set ethtool_link_settings */ @@ -1258,7 +1258,7 @@ struct ethtool_link_settings { #endif #endif // 0 -#ifndef HAVE_STRUCT_FIB_RULE_UID_RANGE +#if ! HAVE_STRUCT_FIB_RULE_UID_RANGE struct fib_rule_uid_range { __u32 start; diff --git a/src/basic/path-util.h b/src/basic/path-util.h index 0d162bac2..ed305e012 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -30,7 +30,7 @@ #define DEFAULT_PATH_NORMAL "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" #define DEFAULT_PATH_SPLIT_USR DEFAULT_PATH_NORMAL ":/sbin:/bin" -#ifdef HAVE_SPLIT_USR +#if HAVE_SPLIT_USR # define DEFAULT_PATH DEFAULT_PATH_SPLIT_USR #else # define DEFAULT_PATH DEFAULT_PATH_NORMAL diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 62c7acfa2..708b45aa0 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -27,13 +27,14 @@ #include #include #include +#include #include #include #include #include #include #include -#ifdef HAVE_VALGRIND_VALGRIND_H +#if HAVE_VALGRIND_VALGRIND_H #include #endif @@ -48,6 +49,7 @@ #include "macro.h" #include "missing.h" #include "process-util.h" +//#include "raw-clone.h" #include "signal-util.h" //#include "stat-util.h" #include "string-table.h" @@ -478,7 +480,7 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) { assert(field); assert(uid); - if (pid < 0) + if (!pid_is_valid(pid)) return -EINVAL; p = procfs_file_alloca(pid, "status"); @@ -793,7 +795,7 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) { bool pid_is_unwaited(pid_t pid) { /* Checks whether a PID is still valid at all, including a zombie */ - if (pid < 0) + if (!pid_is_valid(pid)) return false; if (pid <= 1) /* If we or PID 1 would be dead and have been waited for, this code would not be running */ @@ -813,7 +815,7 @@ bool pid_is_alive(pid_t pid) { /* Checks whether a PID is still valid and not a zombie */ - if (pid < 0) + if (!pid_is_valid(pid)) return false; if (pid <= 1) /* If we or PID 1 would be a zombie, this code would not be running */ @@ -833,7 +835,7 @@ bool pid_is_alive(pid_t pid) { int pid_from_same_root_fs(pid_t pid) { const char *root; - if (pid < 0) + if (!pid_is_valid(pid)) return false; if (pid == 0 || pid == getpid_cached()) @@ -954,7 +956,7 @@ int opinionated_personality(unsigned long *ret) { } void valgrind_summary_hack(void) { -#ifdef HAVE_VALGRIND_VALGRIND_H +#if HAVE_VALGRIND_VALGRIND_H if (getpid_cached() == 1 && RUNNING_ON_VALGRIND) { pid_t pid; pid = raw_clone(SIGCHLD); diff --git a/src/basic/random-util.c b/src/basic/random-util.c index 42f484d68..146c8f55e 100644 --- a/src/basic/random-util.c +++ b/src/basic/random-util.c @@ -26,11 +26,11 @@ #include #include -#ifdef HAVE_SYS_AUXV_H +#if HAVE_SYS_AUXV_H # include #endif -#ifdef USE_SYS_RANDOM_H +#if USE_SYS_RANDOM_H # include #else # include @@ -100,14 +100,14 @@ int acquire_random_bytes(void *p, size_t n, bool high_quality_required) { void initialize_srand(void) { static bool srand_called = false; unsigned x; -#ifdef HAVE_SYS_AUXV_H +#if HAVE_SYS_AUXV_H void *auxv; #endif if (srand_called) return; -#ifdef HAVE_SYS_AUXV_H +#if HAVE_SYS_AUXV_H /* The kernel provides us with 16 bytes of entropy in auxv, so let's * try to make use of that to seed the pseudo-random generator. It's * better than nothing... */ diff --git a/src/basic/selinux-util.c b/src/basic/selinux-util.c index c7a04ad76..51b807b85 100644 --- a/src/basic/selinux-util.c +++ b/src/basic/selinux-util.c @@ -26,7 +26,7 @@ #include #include -#ifdef HAVE_SELINUX +#if HAVE_SELINUX #include #include #include @@ -40,7 +40,7 @@ #include "time-util.h" #include "util.h" -#ifdef HAVE_SELINUX +#if HAVE_SELINUX DEFINE_TRIVIAL_CLEANUP_FUNC(char*, freecon); DEFINE_TRIVIAL_CLEANUP_FUNC(context_t, context_free); @@ -54,7 +54,7 @@ static struct selabel_handle *label_hnd = NULL; #endif bool mac_selinux_use(void) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (cached_use < 0) cached_use = is_selinux_enabled() > 0; @@ -65,7 +65,7 @@ bool mac_selinux_use(void) { } void mac_selinux_retest(void) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX cached_use = -1; #endif } @@ -73,7 +73,7 @@ void mac_selinux_retest(void) { int mac_selinux_init(void) { int r = 0; -#ifdef HAVE_SELINUX +#if HAVE_SELINUX usec_t before_timestamp, after_timestamp; struct mallinfo before_mallinfo, after_mallinfo; @@ -110,7 +110,7 @@ int mac_selinux_init(void) { void mac_selinux_finish(void) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (!label_hnd) return; @@ -121,7 +121,7 @@ void mac_selinux_finish(void) { int mac_selinux_fix(const char *path, bool ignore_enoent, bool ignore_erofs) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX struct stat st; int r; @@ -170,7 +170,7 @@ int mac_selinux_fix(const char *path, bool ignore_enoent, bool ignore_erofs) { #if 0 /// UNNEDED by elogind int mac_selinux_apply(const char *path, const char *label) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (!mac_selinux_use()) return 0; @@ -189,7 +189,7 @@ int mac_selinux_apply(const char *path, const char *label) { int mac_selinux_get_create_label_from_exe(const char *exe, char **label) { int r = -EOPNOTSUPP; -#ifdef HAVE_SELINUX +#if HAVE_SELINUX _cleanup_freecon_ char *mycon = NULL, *fcon = NULL; security_class_t sclass; @@ -221,7 +221,7 @@ int mac_selinux_get_our_label(char **label) { assert(label); -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (!mac_selinux_use()) return -EOPNOTSUPP; @@ -236,7 +236,7 @@ int mac_selinux_get_our_label(char **label) { int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *exec_label, char **label) { int r = -EOPNOTSUPP; -#ifdef HAVE_SELINUX +#if HAVE_SELINUX _cleanup_freecon_ char *mycon = NULL, *peercon = NULL, *fcon = NULL; _cleanup_context_free_ context_t pcon = NULL, bcon = NULL; security_class_t sclass; @@ -297,7 +297,7 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char * char* mac_selinux_free(char *label) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (!label) return NULL; @@ -314,7 +314,7 @@ char* mac_selinux_free(char *label) { int mac_selinux_create_file_prepare(const char *path, mode_t mode) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX _cleanup_freecon_ char *filecon = NULL; int r; @@ -357,7 +357,7 @@ int mac_selinux_create_file_prepare(const char *path, mode_t mode) { void mac_selinux_create_file_clear(void) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX PROTECT_ERRNO; if (!mac_selinux_use()) @@ -370,7 +370,7 @@ void mac_selinux_create_file_clear(void) { #if 0 /// UNNEEDED by elogind int mac_selinux_create_socket_prepare(const char *label) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (!mac_selinux_use()) return 0; @@ -389,7 +389,7 @@ int mac_selinux_create_socket_prepare(const char *label) { void mac_selinux_create_socket_clear(void) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX PROTECT_ERRNO; if (!mac_selinux_use()) @@ -403,7 +403,7 @@ int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) { /* Binds a socket and label its file system object according to the SELinux policy */ -#ifdef HAVE_SELINUX +#if HAVE_SELINUX _cleanup_freecon_ char *fcon = NULL; const struct sockaddr_un *un; bool context_changed = false; diff --git a/src/basic/set.c b/src/basic/set.c new file mode 100644 index 000000000..fd398b821 --- /dev/null +++ b/src/basic/set.c @@ -0,0 +1,61 @@ +/*** + This file is part of systemd. + + Copyright 2017 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include "set.h" + +int set_make(Set **ret, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS, void *add, ...) { + _cleanup_set_free_ Set *s = NULL; + int r; + + assert(ret); + + s = set_new(hash_ops HASHMAP_DEBUG_PASS_ARGS); + if (!s) + return -ENOMEM; + + if (add) { + va_list ap; + + r = set_put(s, add); + if (r < 0) + return r; + + va_start(ap, add); + + for(;;) { + void *arg = va_arg(ap, void*); + + if (!arg) + break; + + r = set_put(s, arg); + if (r < 0) { + va_end(ap); + return r; + } + } + + va_end(ap); + } + + *ret = s; + s = NULL; + + return 0; +} diff --git a/src/basic/smack-util.c b/src/basic/smack-util.c index 9bcc4a3a2..46ec68975 100644 --- a/src/basic/smack-util.c +++ b/src/basic/smack-util.c @@ -35,7 +35,7 @@ #include "string-table.h" #include "xattr-util.h" -#ifdef HAVE_SMACK +#if HAVE_SMACK bool mac_smack_use(void) { static int cached_use = -1; diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index fec5ee12e..3d622bb1c 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -48,7 +48,7 @@ #include "util.h" #if 0 /// UNNEEDED by elogind -#ifdef ENABLE_IDN +#if ENABLE_IDN # define IDN_FLAGS (NI_IDN|NI_IDN_USE_STD3_ASCII_RULES) #else # define IDN_FLAGS 0 diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index b83e778b2..d205870c2 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -47,7 +47,6 @@ #include "log.h" #include "macro.h" #include "parse-util.h" -#include "path-util.h" #include "process-util.h" #include "socket-util.h" #include "stat-util.h" @@ -57,6 +56,9 @@ #include "time-util.h" #include "util.h" +/// Additional includes needed by elogind +#include "path-util.h" + static volatile unsigned cached_columns = 0; static volatile unsigned cached_lines = 0; diff --git a/src/basic/time-util.c b/src/basic/time-util.c index f0b9cc183..fc94c945e 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -861,11 +861,11 @@ parse_usec: } from_tm: - x = mktime_or_timegm(&tm, utc); - if (x < 0) + if (weekday >= 0 && tm.tm_wday != weekday) return -EINVAL; - if (weekday >= 0 && tm.tm_wday != weekday) + x = mktime_or_timegm(&tm, utc); + if (x < 0) return -EINVAL; ret = (usec_t) x * USEC_PER_SEC + x_usec; @@ -895,20 +895,18 @@ typedef struct ParseTimestampResult { } ParseTimestampResult; int parse_timestamp(const char *t, usec_t *usec) { - char *last_space, *timezone = NULL; + char *last_space, *tz = NULL; ParseTimestampResult *shared, tmp; int r; pid_t pid; last_space = strrchr(t, ' '); if (last_space != NULL && timezone_is_valid(last_space + 1)) - timezone = last_space + 1; + tz = last_space + 1; - if (timezone == NULL || endswith_no_case(t, " UTC")) + if (tz == NULL || endswith_no_case(t, " UTC")) return parse_timestamp_impl(t, usec, false); - t = strndupa(t, last_space - t); - shared = mmap(NULL, sizeof *shared, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0); if (shared == MAP_FAILED) return negative_errno(); @@ -922,14 +920,24 @@ int parse_timestamp(const char *t, usec_t *usec) { } if (pid == 0) { - if (setenv("TZ", timezone, 1) != 0) { + bool with_tz = true; + + if (setenv("TZ", tz, 1) != 0) { shared->return_value = negative_errno(); _exit(EXIT_FAILURE); } tzset(); - shared->return_value = parse_timestamp_impl(t, &shared->usec, true); + /* If there is a timezone that matches the tzname fields, leave the parsing to the implementation. + * Otherwise just cut it off */ + with_tz = !STR_IN_SET(tz, tzname[0], tzname[1]); + + /*cut off the timezone if we dont need it*/ + if (with_tz) + t = strndupa(t, last_space - t); + + shared->return_value = parse_timestamp_impl(t, &shared->usec, with_tz); _exit(EXIT_SUCCESS); } diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index a2c5ea1a9..4a5a22f9b 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -67,7 +67,7 @@ typedef struct MountPoint { * fourth (securityfs) is needed by IMA to load a custom policy. The * other ones we can delay until SELinux and IMA are loaded. When * SMACK is enabled we need smackfs, too, so it's a fifth one. */ -#ifdef HAVE_SMACK +#if HAVE_SMACK #define N_EARLY_MOUNT 5 #else #define N_EARLY_MOUNT 4 @@ -83,7 +83,7 @@ static const MountPoint mount_table[] = { NULL, MNT_FATAL|MNT_IN_CONTAINER }, { "securityfs", "/sys/kernel/security", "securityfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL, MNT_NONE }, -#ifdef HAVE_SMACK +#if HAVE_SMACK { "smackfs", "/sys/fs/smackfs", "smackfs", "smackfsdef=*", MS_NOSUID|MS_NOEXEC|MS_NODEV, mac_smack_use, MNT_FATAL }, { "tmpfs", "/dev/shm", "tmpfs", "mode=1777,smackfsroot=*", MS_NOSUID|MS_NODEV|MS_STRICTATIME, @@ -93,7 +93,7 @@ static const MountPoint mount_table[] = { NULL, MNT_FATAL|MNT_IN_CONTAINER }, { "devpts", "/dev/pts", "devpts", "mode=620,gid=" STRINGIFY(TTY_GID), MS_NOSUID|MS_NOEXEC, NULL, MNT_IN_CONTAINER }, -#ifdef HAVE_SMACK +#if HAVE_SMACK { "tmpfs", "/run", "tmpfs", "mode=755,smackfsroot=*", MS_NOSUID|MS_NODEV|MS_STRICTATIME, mac_smack_use, MNT_FATAL }, #endif @@ -117,7 +117,7 @@ static const MountPoint mount_table[] = { cg_is_legacy_wanted, MNT_FATAL|MNT_IN_CONTAINER }, { "pstore", "/sys/fs/pstore", "pstore", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL, MNT_NONE }, -#ifdef ENABLE_EFI +#if ENABLE_EFI { "efivarfs", "/sys/firmware/efi/efivars", "efivarfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV, is_efi_boot, MNT_NONE }, #endif @@ -351,7 +351,7 @@ int mount_cgroup_controllers(char ***join_controllers) { return 0; } -#if defined(HAVE_SELINUX) || defined(HAVE_SMACK) +#if HAVE_SELINUX || HAVE_SMACK static int nftw_cb( const char *fpath, const struct stat *sb, @@ -384,7 +384,7 @@ int mount_setup(bool loaded_policy) { return r; #if 0 /// elogind does not control /, /dev, /run and /run/systemd/* are setup elsewhere. -#if defined(HAVE_SELINUX) || defined(HAVE_SMACK) +#if HAVE_SELINUX || HAVE_SMACK /* Nodes in devtmpfs and /run need to be manually updated for * the appropriate labels, after mounting. The other virtual * API file systems like /sys and /proc do not need that, they diff --git a/src/libelogind/sd-bus/bus-control.c b/src/libelogind/sd-bus/bus-control.c index 226e54e03..23f83a631 100644 --- a/src/libelogind/sd-bus/bus-control.c +++ b/src/libelogind/sd-bus/bus-control.c @@ -17,7 +17,7 @@ along with systemd; If not, see . ***/ -#ifdef HAVE_VALGRIND_MEMCHECK_H +#if HAVE_VALGRIND_MEMCHECK_H #include #endif diff --git a/src/libelogind/sd-bus/bus-kernel.c b/src/libelogind/sd-bus/bus-kernel.c index 43032efd1..edb9b6460 100644 --- a/src/libelogind/sd-bus/bus-kernel.c +++ b/src/libelogind/sd-bus/bus-kernel.c @@ -17,7 +17,7 @@ along with systemd; If not, see . ***/ -#ifdef HAVE_VALGRIND_MEMCHECK_H +#if HAVE_VALGRIND_MEMCHECK_H #include #endif diff --git a/src/libelogind/sd-bus/sd-bus.c b/src/libelogind/sd-bus/sd-bus.c index a674b9ea8..107fc363c 100644 --- a/src/libelogind/sd-bus/sd-bus.c +++ b/src/libelogind/sd-bus/sd-bus.c @@ -53,6 +53,9 @@ #include "strv.h" #include "util.h" +/// Additional includes needed by elogind +#include "process-util.h" + #define log_debug_bus_message(m) \ do { \ sd_bus_message *_mm = (m); \ diff --git a/src/libelogind/sd-daemon/sd-daemon.c b/src/libelogind/sd-daemon/sd-daemon.c index 78274e167..87e7f7842 100644 --- a/src/libelogind/sd-daemon/sd-daemon.c +++ b/src/libelogind/sd-daemon/sd-daemon.c @@ -42,6 +42,9 @@ #include "strv.h" #include "util.h" +/// Additional includes needed by elogind +#include "process-util.h" + #define SNDBUF_SIZE (8*1024*1024) static void unsetenv_all(bool unset_environment) { diff --git a/src/login/logind-acl.h b/src/login/logind-acl.h index 5587becca..df25beca2 100644 --- a/src/login/logind-acl.h +++ b/src/login/logind-acl.h @@ -28,7 +28,7 @@ #include #endif // 0 -#ifdef HAVE_ACL +#if HAVE_ACL int devnode_acl(const char *path, bool flush, diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 4d75e3e15..63cd1a4d4 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -348,7 +348,7 @@ static int method_get_session_by_pid(sd_bus_message *message, void *userdata, sd r = sd_bus_message_read(message, "u", &pid); if (r < 0) return r; - if (pid < 0) + if (!pid_is_valid((pid_t) pid)) return -EINVAL; if (pid == 0) { @@ -411,7 +411,7 @@ static int method_get_user_by_pid(sd_bus_message *message, void *userdata, sd_bu r = sd_bus_message_read(message, "u", &pid); if (r < 0) return r; - if (pid < 0) + if (!pid_is_valid((pid_t) pid)) return -EINVAL; if (pid == 0) { diff --git a/src/login/logind-session.c b/src/login/logind-session.c index d2125112d..8712dae62 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -33,7 +33,6 @@ #include "bus-error.h" #include "bus-util.h" #include "escape.h" -#include "extract-word.h" #include "fd-util.h" #include "fileio.h" #include "format-util.h" @@ -42,11 +41,14 @@ #include "mkdir.h" #include "parse-util.h" #include "path-util.h" +#include "process-util.h" #include "string-table.h" #include "terminal-util.h" #include "user-util.h" #include "util.h" -#include "process-util.h" + +/// Additional includes needed by elogind +#include "extract-word.h" #define RELEASE_USEC (20*USEC_PER_SEC) diff --git a/src/login/meson.build b/src/login/meson.build index d98b4f43d..aff6e3f2a 100644 --- a/src/login/meson.build +++ b/src/login/meson.build @@ -61,7 +61,7 @@ liblogind_core_sources += [files(''' update_utmp_files] #endif // 1 logind_acl_c = files('logind-acl.c') -if conf.get('HAVE_ACL', false) +if conf.get('HAVE_ACL') == 1 liblogind_core_sources += logind_acl_c endif @@ -89,7 +89,7 @@ loginctl_sources += files(''' '''.split()) #endif // 1 #if 0 /// elogind builds itself unconditionally and with some adaptations -# if conf.get('ENABLE_LOGIND', false) +# if conf.get('ENABLE_LOGIND') == 1 # logind_conf = configure_file( # input : 'logind.conf.in', # output : 'logind.conf', diff --git a/src/shared/acl-util.h b/src/shared/acl-util.h index 133996d77..d4613f33c 100644 --- a/src/shared/acl-util.h +++ b/src/shared/acl-util.h @@ -19,7 +19,7 @@ along with systemd; If not, see . ***/ -#ifdef HAVE_ACL +#if HAVE_ACL #include #include diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index f3579d07e..0fb28c24d 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -257,7 +257,7 @@ int bus_test_polkit( return r; else if (r > 0) return 1; -#ifdef ENABLE_POLKIT +#if ENABLE_POLKIT else { _cleanup_(sd_bus_message_unrefp) sd_bus_message *request = NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; @@ -336,7 +336,7 @@ int bus_test_polkit( return -EACCES; } -#ifdef ENABLE_POLKIT +#if ENABLE_POLKIT typedef struct AsyncPolkitQuery { sd_bus_message *request, *reply; @@ -400,7 +400,7 @@ int bus_verify_polkit_async( Hashmap **registry, sd_bus_error *error) { -#ifdef ENABLE_POLKIT +#if ENABLE_POLKIT _cleanup_(sd_bus_message_unrefp) sd_bus_message *pk = NULL; AsyncPolkitQuery *q; const char *sender, **k, **v; @@ -418,7 +418,7 @@ int bus_verify_polkit_async( if (r != 0) return r; -#ifdef ENABLE_POLKIT +#if ENABLE_POLKIT q = hashmap_get(*registry, call); if (q) { int authorized, challenge; @@ -465,7 +465,7 @@ int bus_verify_polkit_async( else if (r > 0) return 1; -#ifdef ENABLE_POLKIT +#if ENABLE_POLKIT if (sd_bus_get_current_message(call->bus) != call) return -EINVAL; @@ -554,7 +554,7 @@ int bus_verify_polkit_async( } void bus_verify_polkit_async_registry_free(Hashmap *registry) { -#ifdef ENABLE_POLKIT +#if ENABLE_POLKIT AsyncPolkitQuery *q; while ((q = hashmap_steal_first(registry))) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index ab66bfe60..8dff2886c 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -43,6 +43,10 @@ #include "time-util.h" #include "utf8.h" +/// Additional includes needed by elogind +#include "def.h" +#include "fileio.h" + int config_item_table_lookup( const void *table, const char *section, @@ -315,24 +319,44 @@ int config_parse(const char *unit, fd_warn_permissions(filename, fileno(f)); for (;;) { - char buf[LINE_MAX], *l, *p, *c = NULL, *e; + _cleanup_free_ char *buf = NULL; + char *l, *p, *c = NULL, *e; bool escaped = false; - if (!fgets(buf, sizeof buf, f)) { - if (feof(f)) - break; + r = read_line(f, LONG_LINE_MAX, &buf); + if (r == 0) + break; + if (r == -ENOBUFS) { + if (warn) + log_error_errno(r, "%s:%u: Line too long", filename, line); - return log_error_errno(errno, "Failed to read configuration file '%s': %m", filename); + return r; + } + if (r < 0) { + if (warn) + log_error_errno(r, "%s:%u: Error while reading configuration file: %m", filename, line); + + return r; } l = buf; - if (allow_bom && startswith(l, UTF8_BYTE_ORDER_MARK)) - l += strlen(UTF8_BYTE_ORDER_MARK); - allow_bom = false; + if (allow_bom) { + char *q; - truncate_nl(l); + q = startswith(buf, UTF8_BYTE_ORDER_MARK); + if (q) { + l = q; + allow_bom = false; + } + } if (continuation) { + if (strlen(continuation) + strlen(l) > LONG_LINE_MAX) { + if (warn) + log_error("%s:%u: Continuation line too long", filename, line); + return -ENOBUFS; + } + c = strappend(continuation, l); if (!c) { if (warn) @@ -386,8 +410,7 @@ int config_parse(const char *unit, if (r < 0) { if (warn) - log_warning_errno(r, "Failed to parse file '%s': %m", - filename); + log_warning_errno(r, "%s:%u: Failed to parse file: %m", filename, line); return r; } } diff --git a/src/shared/meson.build b/src/shared/meson.build index 06ecaf633..172f55ba7 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -127,20 +127,20 @@ shared_sources = ''' test_tables_h = files('test-tables.h') shared_sources += [test_tables_h] -if conf.get('HAVE_ACL', false) +if conf.get('HAVE_ACL') == 1 shared_sources += ['acl-util.c'] endif -if conf.get('HAVE_UTMP', false) +if conf.get('HAVE_UTMP') == 1 shared_sources += ['utmp-wtmp.c'] endif #if 0 /// UNNEEDED by elogind -# if conf.get('HAVE_SECCOMP', false) +# if conf.get('HAVE_SECCOMP') == 1 # shared_sources += ['seccomp-util.c'] # endif # -# if conf.get('HAVE_LIBIPTC', false) +# if conf.get('HAVE_LIBIPTC') == 1 # shared_sources += ['firewall-util.c'] # endif #endif // 0 diff --git a/src/shared/spawn-polkit-agent.c b/src/shared/spawn-polkit-agent.c index 7dae4d14f..9a4014766 100644 --- a/src/shared/spawn-polkit-agent.c +++ b/src/shared/spawn-polkit-agent.c @@ -33,7 +33,7 @@ #include "time-util.h" #include "util.h" -#ifdef ENABLE_POLKIT +#if ENABLE_POLKIT static pid_t agent_pid = 0; int polkit_agent_open(void) { diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index ed32f0305..e0b8980f3 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -19,12 +19,14 @@ #include -#include "alloc-util.h" #include "fileio.h" #include "log.h" #include "string-util.h" #include "udev-util.h" +/// Additional includes needed by elogind +#include "alloc-util.h" + int udev_parse_config(void) { _cleanup_free_ char *val = NULL; const char *log; diff --git a/src/shared/utmp-wtmp.h b/src/shared/utmp-wtmp.h index 438e270a2..8da594100 100644 --- a/src/shared/utmp-wtmp.h +++ b/src/shared/utmp-wtmp.h @@ -25,7 +25,7 @@ #include "time-util.h" #include "util.h" -#ifdef HAVE_UTMP +#if HAVE_UTMP int utmp_get_runlevel(int *runlevel, int *previous); int utmp_put_shutdown(void); diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 01fa22349..c6dd13197 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -69,7 +69,7 @@ static int write_state(FILE **f, char **states) { STRV_FOREACH(state, states) { int k; - k = write_string_stream(*f, *state, true); + k = write_string_stream(*f, *state, 0); if (k == 0) return 0; log_debug_errno(k, "Failed to write '%s' to /sys/power/state: %m", diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h index 4bc248a4b..8c2348677 100644 --- a/src/systemd/sd-messages.h +++ b/src/systemd/sd-messages.h @@ -103,6 +103,9 @@ _SD_BEGIN_DECLARATIONS; #define SD_MESSAGE_UNIT_RESTART_SCHEDULED_STR \ SD_ID128_MAKE_STR(5e,b0,34,94,b6,58,48,70,a5,36,b3,37,29,08,09,b3) +#define SD_MESSAGE_UNIT_RESOURCES SD_ID128_MAKE(ae,8f,7b,86,6b,03,47,b9,af,31,fe,1c,80,b1,27,c0) +#define SD_MESSAGE_UNIT_RESOURCES_STR SD_ID128_MAKE_STR(ae,8f,7b,86,6b,03,47,b9,af,31,fe,1c,80,b1,27,c0) + #define SD_MESSAGE_SPAWN_FAILED SD_ID128_MAKE(64,12,57,65,1c,1b,4e,c9,a8,62,4d,7a,40,a9,e1,e7) #define SD_MESSAGE_SPAWN_FAILED_STR SD_ID128_MAKE_STR(64,12,57,65,1c,1b,4e,c9,a8,62,4d,7a,40,a9,e1,e7) diff --git a/src/test/meson.build b/src/test/meson.build index c811dd675..a923d6144 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -35,10 +35,10 @@ test_libelogind_sym_c = custom_target( # output : 'test-libudev-sym.c', # command : [generate_sym_test_py, '@INPUT0@', '@INPUT1@'], # capture : true) -# -# test_dlopen_c = files('test-dlopen.c') #endif // 0 +test_dlopen_c = files('test-dlopen.c') + ############################################################ tests += [ @@ -365,6 +365,7 @@ tests += [ [libbasic], []], +#if 0 /// UNNEEDED in elogind # [['src/test/test-bpf.c', # 'src/test/test-helper.c'], # [libcore, @@ -375,6 +376,7 @@ tests += [ # libseccomp, # libselinux, # libblkid]], +#endif // 0 [['src/test/test-hashmap.c', 'src/test/test-hashmap-plain.c', diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c index a66ed1bd3..17d12ec76 100644 --- a/src/test/test-conf-parser.c +++ b/src/test/test-conf-parser.c @@ -24,13 +24,15 @@ #include "strv.h" #include "util.h" +/// Additional includes needed by elogind +#include "fd-util.h" +#include "fileio.h" + static void test_config_parse_path_one(const char *rvalue, const char *expected) { - char *path = NULL; + _cleanup_free_ char *path = NULL; assert_se(config_parse_path("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &path, NULL) >= 0); assert_se(streq_ptr(expected, path)); - - free(path); } static void test_config_parse_log_level_one(const char *rvalue, int expected) { @@ -80,12 +82,10 @@ static void test_config_parse_unsigned_one(const char *rvalue, unsigned expected } static void test_config_parse_strv_one(const char *rvalue, char **expected) { - char **strv = 0; + _cleanup_strv_free_ char **strv = NULL; assert_se(config_parse_strv("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &strv, NULL) >= 0); assert_se(strv_equal(expected, strv)); - - strv_free(strv); } static void test_config_parse_mode_one(const char *rvalue, mode_t expected) { @@ -239,7 +239,130 @@ static void test_config_parse_iec_uint64(void) { } #endif // 0 +#define x10(x) x x x x x x x x x x +#define x100(x) x10(x10(x)) +#define x1000(x) x10(x100(x)) + +static const char* const config_file[] = { + "[Section]\n" + "setting1=1\n", + + "[Section]\n" + "setting1=1", /* no terminating newline */ + + "\n\n\n\n[Section]\n\n\n" + "setting1=1", /* some whitespace, no terminating newline */ + + "[Section]\n" + "[Section]\n" + "setting1=1\n" + "setting1=2\n" + "setting1=1\n", /* repeated settings */ + + "[Section]\n" + "setting1=1\\\n" /* normal continuation */ + "2\\\n" + "3\n", + + "[Section]\n" + "setting1=1\\\\\\\n" /* continuation with trailing escape symbols */ + "\\\\2\n", /* note that C requires one level of escaping, so the + * parser gets "…1 BS BS BS NL BS BS 2 NL", which + * it translates into "…1 BS BS SP BS BS 2" */ + + "\n[Section]\n\n" + "setting1=" /* a line above LINE_MAX length */ + x1000("ABCD") + "\n", + + "[Section]\n" + "setting1=" /* a line above LINE_MAX length, with continuation */ + x1000("ABCD") "\\\n" + "foobar", + + "[Section]\n" + "setting1=" /* a line above the allowed limit: 9 + 1050000 + 1 */ + x1000(x1000("x") x10("abcde")) "\n", + + "[Section]\n" + "setting1=" /* many continuation lines, together above the limit */ + x1000(x1000("x") x10("abcde") "\\\n") "xxx", +}; + +static void test_config_parse(unsigned i, const char *s) { + char name[] = "/tmp/test-conf-parser.XXXXXX"; + int fd, r; + _cleanup_fclose_ FILE *f = NULL; + _cleanup_free_ char *setting1 = NULL; + + const ConfigTableItem items[] = { + { "Section", "setting1", config_parse_string, 0, &setting1}, + {} + }; + + log_info("== %s[%i] ==", __func__, i); + + fd = mkostemp_safe(name); + assert_se(fd >= 0); + assert_se((size_t) write(fd, s, strlen(s)) == strlen(s)); + + assert_se(lseek(fd, 0, SEEK_SET) == 0); + assert_se(f = fdopen(fd, "r")); + + /* + int config_parse(const char *unit, + const char *filename, + FILE *f, + const char *sections, + ConfigItemLookup lookup, + const void *table, + bool relaxed, + bool allow_include, + bool warn, + void *userdata) + */ + + r = config_parse(NULL, name, f, + "Section\0", + config_item_table_lookup, items, + false, false, true, NULL); + + switch (i) { + case 0 ... 3: + assert_se(r == 0); + assert_se(streq(setting1, "1")); + break; + + case 4: + assert_se(r == 0); + assert_se(streq(setting1, "1 2 3")); + break; + + case 5: + assert_se(r == 0); + assert_se(streq(setting1, "1\\\\ \\\\2")); + break; + + case 6: + assert_se(r == 0); + assert_se(streq(setting1, x1000("ABCD"))); + break; + + case 7: + assert_se(r == 0); + assert_se(streq(setting1, x1000("ABCD") " foobar")); + break; + + case 8 ... 9: + assert_se(r == -ENOBUFS); + assert_se(setting1 == NULL); + break; + } +} + int main(int argc, char **argv) { + unsigned i; + log_parse_environment(); log_open(); @@ -262,5 +385,8 @@ int main(int argc, char **argv) { test_config_parse_iec_uint64(); #endif // 0 + for (i = 0; i < ELEMENTSOF(config_file); i++) + test_config_parse(i, config_file[i]); + return 0; } diff --git a/src/test/test-dlopen.c b/src/test/test-dlopen.c new file mode 100644 index 000000000..9f5343a7e --- /dev/null +++ b/src/test/test-dlopen.c @@ -0,0 +1,32 @@ +/*** + This file is part of systemd. + + Copyright 2016 Zbigniew Jędrzejewski-Szmek + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include +#include + +#include "macro.h" + +int main(int argc, char **argv) { + void *handle; + + assert_se((handle = dlopen(argv[1], RTLD_NOW))); + assert_se(dlclose(handle) == 0); + + return EXIT_SUCCESS; +} diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 19ffe01d7..c573f4127 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -26,7 +26,7 @@ #include #include #include -#ifdef HAVE_VALGRIND_VALGRIND_H +#if HAVE_VALGRIND_VALGRIND_H #include #endif @@ -176,7 +176,7 @@ static void test_get_process_cmdline_harder(void) { if (geteuid() != 0) return; -#ifdef HAVE_VALGRIND_VALGRIND_H +#if HAVE_VALGRIND_VALGRIND_H /* valgrind patches open(/proc//cmdline) * so, test_get_process_cmdline_harder fails always * See https://github.com/systemd/systemd/pull/3555#issuecomment-226564908 */ @@ -376,7 +376,7 @@ static void test_rename_process_now(const char *p, int ret) { if (r < 0) return; -#ifdef HAVE_VALGRIND_VALGRIND_H +#if HAVE_VALGRIND_VALGRIND_H /* see above, valgrind is weird, we can't verify what we are doing here */ if (RUNNING_ON_VALGRIND) return; diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index ec5682e66..fc00845ab 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -21,7 +21,7 @@ #include #include -#ifdef HAVE_AUDIT +#if HAVE_AUDIT #include #endif @@ -30,10 +30,12 @@ //#include "alloc-util.h" #include "bus-error.h" //#include "bus-util.h" -//#include "formats-util.h" +//#include "format-util.h" //#include "log.h" //#include "macro.h" +#include "process-util.h" //#include "special.h" +#include "strv.h" //#include "unit-name.h" //#include "util.h" #include "utmp-wtmp.h" @@ -44,7 +46,7 @@ #include "update-utmp.h" typedef struct Context { sd_bus *bus; -#ifdef HAVE_AUDIT +#if HAVE_AUDIT int audit_fd; #endif } Context; @@ -129,7 +131,7 @@ static int on_reboot(Context *c) { /* We finished start-up, so let's write the utmp * record and send the audit msg */ -#ifdef HAVE_AUDIT +#if HAVE_AUDIT if (c->audit_fd >= 0) if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_BOOT, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM) { @@ -162,7 +164,7 @@ static int on_shutdown(Context *c) { /* We started shut-down, so let's write the utmp * record and send the audit msg */ -#ifdef HAVE_AUDIT +#if HAVE_AUDIT if (c->audit_fd >= 0) if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM) { @@ -207,7 +209,7 @@ static int on_runlevel(Context *c) { if (previous == runlevel) return 0; -#ifdef HAVE_AUDIT +#if HAVE_AUDIT if (c->audit_fd >= 0) { _cleanup_free_ char *s = NULL; @@ -237,7 +239,7 @@ int main(int argc, char *argv[]) { void update_utmp(int argc, char* argv[], sd_bus *bus) { #endif // 0 Context c = { -#ifdef HAVE_AUDIT +#if HAVE_AUDIT .audit_fd = -1 #endif }; @@ -265,7 +267,7 @@ void update_utmp(int argc, char* argv[], sd_bus *bus) { assert(bus); #endif // 0 -#ifdef HAVE_AUDIT +#if HAVE_AUDIT /* If the kernel lacks netlink or audit support, * don't worry about it. */ c.audit_fd = audit_open(); @@ -303,7 +305,7 @@ finish: else if (streq(argv[1], "shutdown")) (void)on_shutdown(&c); #endif // 0 -#ifdef HAVE_AUDIT +#if HAVE_AUDIT if (c.audit_fd >= 0) audit_close(c.audit_fd); #endif