Skip to content

Commit fb28095

Browse files
authored
Library part7 (#295)
* Add lsof_select_process_regex * Add lsof_select_pid/pgid * Add lsof_select_uid/login
1 parent 437824c commit fb28095

5 files changed

Lines changed: 442 additions & 279 deletions

File tree

include/lsof.h

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,72 @@ enum lsof_error lsof_logic_and(struct lsof_context *ctx);
472472
enum lsof_error lsof_select_process(struct lsof_context *ctx, char *command,
473473
int exclude);
474474

475+
/** Ask lsof to select process by matching regex
476+
*
477+
* Select process executing the command that matches with the
478+
* `regex`.
479+
*
480+
* `regex` must begin and end with a slash ('/'), the characters between the
481+
* slashes are interpreted as a regular expression.
482+
*
483+
* The closing slash may be followed by these modifiers:
484+
* - b the regular expression is a basic one.
485+
* - i ignore the case of letters.
486+
* - x the regular expression is an extended one (default).
487+
*
488+
* You can call this function multiple times to add more search conditions.
489+
*
490+
* \since API version 1
491+
*/
492+
enum lsof_error lsof_select_process_regex(struct lsof_context *ctx,
493+
char *regex);
494+
495+
/** Ask lsof to select process by pid (process id)
496+
*
497+
* Select process by comparing pid. You can specify exclusion by setting
498+
* `exclude` to 1.
499+
*
500+
* You can call this function multiple times to add more search conditions.
501+
*
502+
* \since API version 1
503+
*/
504+
enum lsof_error lsof_select_pid(struct lsof_context *ctx, uint32_t pid,
505+
int exclude);
506+
507+
/** Ask lsof to select process by pgid (process group id)
508+
*
509+
* Select process by comparing pgid. You can specify exclusion by setting
510+
* `exclude` to 1.
511+
*
512+
* You can call this function multiple times to add more search conditions.
513+
*
514+
* \since API version 1
515+
*/
516+
enum lsof_error lsof_select_pgid(struct lsof_context *ctx, uint32_t pgid,
517+
int exclude);
518+
519+
/** Ask lsof to select process by uid
520+
*
521+
* Select process whose user id equals to or not equals to `uid`
522+
*
523+
* You can call this function multiple times to add more search conditions.
524+
*
525+
* \since API version 1
526+
*/
527+
enum lsof_error lsof_select_uid(struct lsof_context *ctx, uint32_t uid,
528+
int exclude);
529+
530+
/** Ask lsof to select process by user login
531+
*
532+
* Select process whose user login name equals to or not equals to `login`
533+
*
534+
* You can call this function multiple times to add more search conditions.
535+
*
536+
* \since API version 1
537+
*/
538+
enum lsof_error lsof_select_login(struct lsof_context *ctx, char *login,
539+
int exclude);
540+
475541
/** Freeze the lsof context
476542
*
477543
* You can only call it once per context. After this call, no more options can
@@ -503,7 +569,7 @@ enum lsof_error lsof_gather(struct lsof_context *ctx,
503569
/** Destroy a lsof context
504570
*
505571
* You should call `lsof_free_result` to free all `struct lsof_result`
506-
* before destorying the context.
572+
* before destroying the context.
507573
*
508574
* You must not use the context anymore after this call.
509575
*

lib/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ struct lsof_context {
14631463
# define Cmdni (ctx->sel_cmd_incl)
14641464
# define Cmdnx (ctx->sel_cmd_excl)
14651465
# define CmdRx (ctx->cmd_regex)
1466+
# define NCmdRxA (ctx->cmd_regex_cap)
14661467
# define NCmdRxU (ctx->cmd_regex_size)
14671468
/* select by network address */
14681469
# define Nwad (ctx->sel_net_addr)

0 commit comments

Comments
 (0)