aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil/libutil.h
Commit message (Collapse)AuthorAgeFilesLines
* libutil: Drop auth_getval()Dag-Erling Smørgrav9 hours1-1/+0
| | | | | | | | | This function has been an empty stub for years; now that we're bumping the library version, we can finally get rid of it. Fixes: 0c381b7f0570 Reviewed by: kib, emaste Differential Revision: https://reviews.freebsd.org/D51704
* libutil: Really fix expand_number(3)Dag-Erling Smørgrav12 hours1-1/+1
| | | | | | | | | | | | | | | | | | It is unclear whether this function was originally intended to support negative numbers. The original implementation used signed integers, but actually giving it a negative number as input would have invoked undefined behavior, and the comments (since removed) only mentioned positive numbers. Fifteen years ago, I “fixed” this by changing the type from signed to unsigned. However, it would still have accepted an input with a leading minus sign (though it would have returned its absolute value). Fifteen years on, change the type back to signed and fix the logic so it correctly handles both positive and negative numbers without invoking undefined behavior. This makes it a better match for humanize_number(3), which it is supposed to complement. Fixes: bbb2703b4f46 Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D51542
* libutil: Move cpuset(1) domain policy parsing code into libutilBojan Novković6 days1-1/+7
| | | | | | | | | | | | | | cpuset(1) implements a domainset(9) policy parser that is used to translate a <policy>:<domain_list> string into a domainset_t mask and a valid domainset policy. This change moves the domainset parsing code into a new cpuset.c function - 'domainset_parselist'. The existing cpuset.c code was refactored into a generalized list parsing function which is now used to parse both CPU sets and domain sets. This is the same approach used in cpuset(1). Reviewed by: markj, ziaee (manpages) Differential Revision: https://reviews.freebsd.org/D46607
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* cpuset(3): Move cpuset's parselist function into libutilBaptiste Daroussin2023-06-011-0/+8
| | | | | | | | | | | | | | In order to allow to add cpuset(2) functionality to more utilities than just cpuset(1) move the parselist code into libutil While here, make the code a little more "library" friendly, by returning a range of various errors so that the consumer can check for them and report appropriate error message to the users (One of the planed usage is the jail(8) utility) Reviewed by: jilles Differential Revision: https://reviews.freebsd.org/D12873
* pidfile: add pidfile_signalMateusz Guzik2022-04-091-0/+1
| | | | Differential Revision: https://reviews.freebsd.org/D34681
* libutil: add kinfo_getswapvmobject(3)Konstantin Belousov2021-10-261-0/+2
| | | | | | | | | which is the wrapper around the vm.swap_objects sysctl, same as kinfo_getvmobject(3) wraps vm.objects. Submitted by: Yoshihiro Ota MFC after: 1 week Differential revision: https://reviews.freebsd.org/D29754
* Add function getlocalbase() to libutil.Stefan Eßer2020-11-181-0/+2
| | | | | | | | | | | | | | | | | | This function returns the path to the local software base directory, by default "/usr/local" (or the value of _PATH_LOCALBASE in include/paths.h when building the world). The value returned can be overridden by 2 methods: - the LOCALBASE environment variable (ignored by SUID programs) - else a non-default user.localbase sysctl value Reviewed by: hps (earlier version) Relnotes: yes Differential Revision: https://reviews.freebsd.org/D27236 Notes: svn path=/head/; revision=367813
* Revert the whole getlocalbase() set of changes while a different design isScott Long2020-11-151-6/+0
| | | | | | | hashed out. Notes: svn path=/head/; revision=367711
* Fix a problem with r367686 related to the use of ssize_t. Not sure how thisScott Long2020-11-141-0/+5
| | | | | | | | | escaped prior testing, but it should be better now. Reported by: lots Notes: svn path=/head/; revision=367689
* Add the library function getlocalbase and its manual page. This helps toScott Long2020-11-141-0/+1
| | | | | | | | | | | unify the retrieval of the various ways that the local software base directory, typically "/usr/local", is expressed in the system. Reviewed by: se Differential Revision: https://reviews.freebsd.org/D27022 Notes: svn path=/head/; revision=367686
* Make pw_scan(3) more compatible with getpwent(3) et. al. when processingIan Lepore2018-07-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | data from /etc/passwd rather than /etc/master.passwd. The libc getpwent(3) and related functions automatically read master.passwd when run by root, or passwd when run by a non-root user. When run by non- root, getpwent() copes with the missing data by setting the corresponding fields in the passwd struct to known values (zeroes for numbers, or a pointer to an empty string for literals). When libutil's pw_scan(3) was used to parse a line without the root-accessible data, it was leaving garbage in the corresponding fields. These changes rename the static pw_init() function used by getpwent() and friends to __pw_initpwd(), and move it into pw_scan.c so that common init code can be shared between libc and libutil. pw_scan(3) now calls __pw_initpwd() before __pw_scan(), just like the getpwent() family does, so that reading an arbitrary passwd file in either format and parsing it with pw_scan(3) returns the same results as getpwent(3) would. This also adds a new pw_initpwd(3) function to libutil, so that code which creates passwd structs from scratch in some manner that doesn't involve pw_scan() can initialize the struct to the values expected by lots of existing code, which doesn't expect to encounter NULL pointers or garbage values in some fields. Notes: svn path=/head/; revision=336746
* lib: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-261-1/+3
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using mis-identified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326219
* Introduce the flopenat(3) function.Mariusz Zaborski2017-08-041-0/+1
| | | | | | | | Reviewed by: des, emaste Differential Revision: https://reviews.freebsd.org/D11690 Notes: svn path=/head/; revision=322054
* revert r283969,283970 not needed anymore after r283981Baptiste Daroussin2015-06-041-4/+0
| | | | Notes: svn path=/head/; revision=283984
* Add a pw_mkdb2(3) function which does the same thing as pw_mkdb(3) exceptBaptiste Daroussin2015-06-031-0/+4
| | | | | | | | | | | it takes a new argument allowing to specify the endianness of the database to generate Differential Revision: https://reviews.freebsd.org/D2730 Reviewed by: ian Notes: svn path=/head/; revision=283969
* Export a list of VM objects in the system via a sysctl. The list can beJohn Baldwin2015-05-271-0/+2
| | | | | | | | | | | | | examined via 'vmstat -o'. It can be used to determine which files are using physical pages of memory and how much each is using. Differential Revision: https://reviews.freebsd.org/D2277 Reviewed by: alc, kib MFC after: 2 weeks Sponsored by: Norse Corp, Inc. (forward porting to HEAD/10) Notes: svn path=/head/; revision=283624
* Cleanup gr_add() so it does not leak memDiane Bruce2013-03-071-1/+1
| | | | | | | | | | | | This is part of ongoing work on sbin/pw M libutil.h M gr_util.c Approved by: theraven Notes: svn path=/head/; revision=247919
* - Clean up previous gr_add use malloc instead of callocBaptiste Daroussin2012-12-271-1/+1
| | | | | | | | | - Fix tinderbox error Submitted by: db Notes: svn path=/head/; revision=244739
* New gr_add function to provide a clean and safe method to append a new memberBaptiste Daroussin2012-12-271-0/+2
| | | | | | | | | into an existing group. Submitted by: db Notes: svn path=/head/; revision=244736
* Consensus between bde and pjd seemed to be that if the function namesGuy Helmer2012-01-261-8/+8
| | | | | | | | | are lined up, then any * after a long type should appear after the type instead of being in front of the function name on the following line. Notes: svn path=/head/; revision=230601
* Make the comments consistent (capitalization, punctuation, andGuy Helmer2012-01-261-6/+10
| | | | | | | | | format). Requested by bde Notes: svn path=/head/; revision=230600
* Restore the parenthesis that are necessary around the constant values.Guy Helmer2012-01-261-7/+7
| | | | | | | Requested by bde. Notes: svn path=/head/; revision=230599
* Fix more disorder in prototypes and constants.Guy Helmer2012-01-161-46/+43
| | | | | | | | | Fix header comments for each section of constants. Fix whitespace in #define lines. Fix unnecessary parenthesis in constants. Notes: svn path=/head/; revision=230233
* Move struct pidfh definition into pidfile.c, and leave a forward declarationGuy Helmer2012-01-121-12/+6
| | | | | | | | | | | | for pidfh in libutil.h in its place. This allows us to hide the contents of the pidfh structure, and also allowed removal of the "#ifdef _SYS_PARAM_H" guard from around the pidfile_* function prototypes. Suggested by pjd. Notes: svn path=/head/; revision=230037
* More prototype formatting fixes, struct member formatting fixes,Guy Helmer2012-01-121-10/+17
| | | | | | | | | and namespace fix for property_find() prototype. Provided by bde. Notes: svn path=/head/; revision=230011
* Fix prototype formatting (indentation, long lines, and continued lines).Guy Helmer2012-01-111-23/+30
| | | | | | | Requested by bde. Notes: svn path=/head/; revision=229988
* Fix namespace issues with prototype parameter names.Guy Helmer2012-01-111-32/+32
| | | | | | | | | Add missing prototype parameter names. Requested by bde. Notes: svn path=/head/; revision=229986
* Fix forward structure declaration and prototype disorder.Guy Helmer2012-01-111-34/+33
| | | | | | | Requested by bde. Notes: svn path=/head/; revision=229985
* Constify arguments.Pawel Jakub Dawidek2012-01-111-1/+1
| | | | Notes: svn path=/head/; revision=229951
* Add pidfile_fileno() to obtain the file descriptor for an openGuy Helmer2012-01-101-0/+1
| | | | | | | pidfile. Notes: svn path=/head/; revision=229937
* Add new pw_make_v7 to make a passwd line (in v7 format) out of a struct passwdBaptiste Daroussin2012-01-051-0/+1
| | | | | | | | | while here, fix missing parentheses of the return statement of pw_make. Approved by: des (mentor) Notes: svn path=/head/; revision=229572
* Modify pw_copy:Baptiste Daroussin2011-12-151-1/+7
| | | | | | | | | | | | | | | | - if pw is NULL and oldpw is not NULL then the oldpw is deleted - if pw->pw_name != oldpw->pw_name but pw->pw_uid == oldpw->pw_uid then it renames the user add new gr_* functions so now gr_util API is similar to pw_util API, this allow to manipulate groups in a safe way. Reviewed by: des Approved by: des MFC after: 1 month Notes: svn path=/head/; revision=228545
* - Commit work from libprocstat project. These patches add support for runtimeStanislav Sedov2011-05-121-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | file and processes information retrieval from the running kernel via sysctl in the form of new library, libprocstat. The library also supports KVM backend for analyzing memory crash dumps. Both procstat(1) and fstat(1) utilities have been modified to take advantage of the library (as the bonus point the fstat(1) utility no longer need superuser privileges to operate), and the procstat(1) utility is now able to display information from memory dumps as well. The newly introduced fuser(1) utility also uses this library and able to operate via sysctl and kvm backends. The library is by no means complete (e.g. KVM backend is missing vnode name resolution routines, and there're no manpages for the library itself) so I plan to improve it further. I'm commiting it so it will get wider exposure and review. We won't be able to MFC this work as it relies on changes in HEAD, which was introduced some time ago, that break kernel ABI. OTOH we may be able to merge the library with KVM backend if we really need it there. Discussed with: rwatson Notes: svn path=/head/; revision=221807
* Don't duplicate define the stdint types.David E. O'Brien2011-05-051-10/+1
| | | | Notes: svn path=/head/; revision=221502
* Add support for IEE/IEC (and now also SI) power of two notions ofXin LI2011-04-121-0/+2
| | | | | | | | | | | | | prefixes (Ki, Mi, Gi...) for humanize_number(3). Note that applications has to pass HN_IEC_PREFIXES to use this feature for backward compatibility reasons. Reviewed by: arundel MFC after: 2 weeks Notes: svn path=/head/; revision=220582
* expand_number() needs uint64_t, declare it here if not already declared.Pawel Jakub Dawidek2011-03-061-0/+5
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=219344
* Simplify expand_number() by combining the (unrolled) loop with theDag-Erling Smørgrav2010-08-141-1/+1
| | | | | | | | | | switch. Since expand_number() does not accept negative numbers, switch from int64_t to uint64_t; this makes it easier to check for overflow. MFC after: 3 weeks Notes: svn path=/head/; revision=211304
* IFH@204581Dag-Erling Smørgrav2010-03-041-4/+28
|\ | | | | | | Notes: svn path=/projects/quota64/; revision=204708
| * Remove login(3), logout(3) and logwtmp(3) from libutil.Ed Schouten2010-01-131-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | These functions only apply to utmp(5). They cannot be kept intact when moving towards utmpx. The login(3) function would break, because its argument is an utmp structure. The logout(3) and logwtmp(3) functions cannot be used, since they provide a functionality which partially overlaps. Increment SHLIB_MAJOR to 9 to indicate the removal. Notes: svn path=/head/; revision=202216
| * Make <libutil.h> work when included by itself.Ed Schouten2009-12-021-0/+28
| | | | | | | | | | | | | | | | | | | | There are several reasons why it didn't work: - It was missing <sys/cdefs.h> for __BEGIN_DECLS. - It uses various primitive types that were not declared. Notes: svn path=/head/; revision=200035
* | Add and document the quota_convert function which converts between theKirk McKusick2009-12-281-0/+1
| | | | | | | | | | | | | | old 32-bit and the new 64-bit formats. Notes: svn path=/projects/quota64/; revision=201144
* | Add and document new quoat_on and quota_off functions.Kirk McKusick2009-11-161-1/+3
| | | | | | | | Notes: svn path=/projects/quota64/; revision=199328
* | Add quota_maxid which returns the maximum user (or group) identifierKirk McKusick2009-10-201-0/+1
| | | | | | | | | | | | | | | | | | in an associated quotafile. Needed by repquota. Bug fix in quota_read. Notes: svn path=/projects/quota64/; revision=198265
* | Further extend the quotafile API.Dag-Erling Smørgrav2009-09-261-1/+4
| | | | | | | | Notes: svn path=/projects/quota64/; revision=197532
* | Update the quotafile library to manage both active quotas via theKirk McKusick2009-02-141-4/+3
| | | | | | | | | | | | | | | | | | | | | | quotactl(2) interface and inactive quotas by accessing the quota files directly. Update the edquota program to use this new interface as proof of concept. Notes: svn path=/projects/quota64/; revision=188604
* | Make hasquota thread safe.Kirk McKusick2009-02-131-1/+1
| | | | | | | | Notes: svn path=/projects/quota64/; revision=188598
* | Move hasquota() function to libutil.Kirk McKusick2009-02-131-0/+2
| | | | | | | | Notes: svn path=/projects/quota64/; revision=188568
* | WIPDag-Erling Smørgrav2009-01-301-0/+9
|/ | | | Notes: svn path=/projects/quota64/; revision=187914
* Merge user/peter/kinfo branch as of r185547 into head.Peter Wemm2008-12-021-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes struct kinfo_filedesc and kinfo_vmentry such that they are same on both 32 and 64 bit platforms like i386/amd64 and won't require sysctl wrapping. Two new OIDs are assigned. The old ones are available under COMPAT_FREEBSD7 - but it isn't that simple. The superceded interface was never actually released on 7.x. The other main change is to pack the data passed to userland via the sysctl. kf_structsize and kve_structsize are reduced for the copyout. If you have a process with 100,000+ sockets open, the unpacked records require a 132MB+ copyout. With packing, it is "only" ~35MB. (Still seriously unpleasant, but not quite as devastating). A similar problem exists for the vmentry structure - have lots and lots of shared libraries and small mmaps and its copyout gets expensive too. My immediate problem is valgrind. It traditionally achieves this functionality by parsing procfs output, in a packed format. Secondly, when tracing 32 bit binaries on amd64 under valgrind, it uses a cross compiled 32 bit binary which ran directly into the differing data structures in 32 vs 64 bit mode. (valgrind uses this to track file descriptor operations and this therefore affected every single 32 bit binary) I've added two utility functions to libutil to unpack the structures into a fixed record length and to make it a little more convenient to use. Notes: svn path=/head/; revision=185548