From 8e321aba842a3d1b1a9d8b4bfd2d3e2f11f35ce3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 2 Aug 2019 10:01:30 -0600 Subject: [PATCH] sched/: Correct some naming. The NuttX task groups have been using the acroynum 'gid' and also the type 'gid_t' for the the task group ID. That is incorrect. Than naming is reserved for use with group permissions. So these were all named to grpid and grpid_t so that it is clearer that these refer to NuttX task group IDs, and not to group permissions. --- fs/procfs/fs_procfsproc.c | 8 ++++---- include/nuttx/sched.h | 14 ++++++++++---- sched/group/group.h | 15 +++++++++------ sched/group/group_addrenv.c | 18 +++++++++--------- sched/group/group_create.c | 25 +++++++++++++------------ sched/group/group_find.c | 11 ++++++----- sched/group/group_leave.c | 4 ++-- sched/sched/sched_waitid.c | 4 ++-- sched/sched/sched_waitpid.c | 6 +++--- sched/task/task_exithook.c | 8 ++++---- sched/task/task_reparent.c | 21 +++++++++++---------- sched/task/task_setup.c | 2 +- 12 files changed, 74 insertions(+), 62 deletions(-) diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 3fbf1e6ffb..a2aa1775b8 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/procfs/fs_procfsproc.c * - * Copyright (C) 2013-2018 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2019 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -513,7 +513,7 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile, #ifdef HAVE_GROUPID linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", "Group:", - group->tg_pgid); + group->tg_pgrpid); #else linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", "PPID:", group->tg_ppid); @@ -930,7 +930,7 @@ static ssize_t proc_groupstatus(FAR struct proc_file_s *procfile, #ifdef HAVE_GROUP_MEMBERS linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", - "Group ID:", group->tg_gid); + "Group ID:", group->tg_grpid); copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, &offset); totalsize += copysize; @@ -943,7 +943,7 @@ static ssize_t proc_groupstatus(FAR struct proc_file_s *procfile, } linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", - "Parent ID:", group->tg_pgid); + "Parent ID:", group->tg_pgrpid); copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, &offset); totalsize += copysize; diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 8ce013d157..4c392a59dc 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -1,7 +1,7 @@ /******************************************************************************** * include/nuttx/sched.h * - * Copyright (C) 2007-2016, 2018 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2016, 2018-2019 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -361,6 +361,12 @@ struct pthread_cleanup_s # endif #endif +/* type grpid_t ******************************************************************/ + +/* The task group ID */ + +typedef int16_t grpid_t; + /* struct dspace_s ***************************************************************/ /* This structure describes a reference counted D-Space region. This must be a @@ -425,10 +431,10 @@ struct task_group_s { #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) struct task_group_s *flink; /* Supports a singly linked list */ - gid_t tg_gid; /* The ID of this task group */ + grpid_t tg_grpid; /* The ID of this task group */ #endif #ifdef HAVE_GROUP_MEMBERS - gid_t tg_pgid; /* The ID of the parent task group */ + grpid_t tg_pgrpid; /* The ID of the parent task group */ #endif #if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SCHED_HAVE_PARENT) pid_t tg_task; /* The ID of the task within the group */ @@ -479,7 +485,7 @@ struct task_group_s #endif #ifndef HAVE_GROUP_MEMBERS - /* REVISIT: What if parent thread exits? Should use tg_pgid. */ + /* REVISIT: What if parent thread exits? Should use tg_pgrpid. */ pid_t tg_ppid; /* This is the ID of the parent thread */ #ifndef CONFIG_SCHED_CHILD_STATUS diff --git a/sched/group/group.h b/sched/group/group.h index 8ba4a28a77..4c7be6dd04 100644 --- a/sched/group/group.h +++ b/sched/group/group.h @@ -1,7 +1,8 @@ /**************************************************************************** * sched/group/group.h * - * Copyright (C) 2007-2013, 2015, 2018 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2013, 2015, 2018-2019 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,14 +49,16 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* Any negative GID is invalid. */ -#define INVALID_GROUP_ID (pid_t)-1 -#define IS_INVALID_GID(gid) ((int)(gid) < 0) +/* Any negative GRPID is invalid. */ + +#define INVALID_GROUP_ID (pid_t)-1 +#define IS_INVALID_GRPID(grpid) ((int)(grpid) < 0) /**************************************************************************** * Public Type Definitions @@ -81,7 +84,7 @@ extern FAR struct task_group_s *g_grouphead; * This must only be accessed with interrupts disabled. */ -extern gid_t g_gid_current; +extern grpid_t g_grpid_current; #endif /**************************************************************************** @@ -107,7 +110,7 @@ void group_delwaiter(FAR struct task_group_s *group); #endif #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) -FAR struct task_group_s *group_findbygid(gid_t gid); +FAR struct task_group_s *group_findby_grpid(grpid_t grpid); #endif #ifdef HAVE_GROUP_MEMBERS diff --git a/sched/group/group_addrenv.c b/sched/group/group_addrenv.c index 2d9964f838..0841293aba 100644 --- a/sched/group/group_addrenv.c +++ b/sched/group/group_addrenv.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group_addrenv.c * - * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016, 2019 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -59,7 +59,7 @@ * This must only be accessed with interrupts disabled. */ -gid_t g_gid_current; +grpid_t g_grpid_current; /**************************************************************************** * Public Functions @@ -98,7 +98,7 @@ int group_addrenv(FAR struct tcb_s *tcb) FAR struct task_group_s *group; FAR struct task_group_s *oldgroup; irqstate_t flags; - gid_t gid; + grpid_t grpid; int ret; /* NULL for the tcb means to use the TCB of the task at the head of the @@ -126,21 +126,21 @@ int group_addrenv(FAR struct tcb_s *tcb) /* Get the ID of the group that needs the address environment */ - gid = group->tg_gid; - DEBUGASSERT(gid != 0); + grpid = group->tg_grpid; + DEBUGASSERT(grpid != 0); /* Are we going to change address environments? */ flags = enter_critical_section(); - if (gid != g_gid_current) + if (grpid != g_grpid_current) { /* Yes.. Is there a current address environment in place? */ - if (g_gid_current != 0) + if (g_grpid_current != 0) { /* Find the old group with this ID. */ - oldgroup = group_findbygid(g_gid_current); + oldgroup = group_findby_grpid(g_grpid_current); DEBUGASSERT(oldgroup && (oldgroup->tg_flags & GROUP_FLAG_ADDRENV) != 0); @@ -168,7 +168,7 @@ int group_addrenv(FAR struct tcb_s *tcb) /* Save the new, current group */ - g_gid_current = gid; + g_grpid_current = grpid; } leave_critical_section(flags); diff --git a/sched/group/group_create.c b/sched/group/group_create.c index 3d43f0d95d..e9849ce288 100644 --- a/sched/group/group_create.c +++ b/sched/group/group_create.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group_create.c * - * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016, 2019 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include #include #include +#include #include "environ/environ.h" #include "group/group.h" @@ -64,7 +65,7 @@ /* This is counter that is used to generate unique task group IDs */ #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) -static gid_t g_gidcounter; +static grpid_t g_grpid_counter; #endif /**************************************************************************** @@ -82,7 +83,7 @@ FAR struct task_group_s *g_grouphead; ****************************************************************************/ /**************************************************************************** - * Name: group_assigngid + * Name: group_assign_grpid * * Description: * Create a unique group ID. @@ -100,10 +101,10 @@ FAR struct task_group_s *g_grouphead; ****************************************************************************/ #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) -static void group_assigngid(FAR struct task_group_s *group) +static void group_assign_grpid(FAR struct task_group_s *group) { irqstate_t flags; - gid_t gid; + grpid_t grpid; /* Pre-emption should already be enabled, but lets be paranoid careful */ @@ -116,13 +117,13 @@ static void group_assigngid(FAR struct task_group_s *group) /* Increment the ID counter. This is global data so be extra paranoid. */ flags = enter_critical_section(); - gid = ++g_gidcounter; + grpid = ++g_grpid_counter; /* Check for overflow */ - if (gid <= 0) + if (grpid <= 0) { - g_gidcounter = 1; + g_grpid_counter = 1; leave_critical_section(flags); } else @@ -130,11 +131,11 @@ static void group_assigngid(FAR struct task_group_s *group) /* Does a task group with this ID already exist? */ leave_critical_section(flags); - if (group_findbygid(gid) == NULL) + if (group_findby_grpid(grpid) == NULL) { /* Now assign this ID to the group and return */ - group->tg_gid = gid; + group->tg_grpid = grpid; sched_unlock(); return; } @@ -222,11 +223,11 @@ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype) tcb->cmn.group = group; #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) - /* Assign the group a unique ID. If g_gidcounter were to wrap before we + /* Assign the group a unique ID. If g_grpid_counter were to wrap before we * finish with task creation, that would be a problem. */ - group_assigngid(group); + group_assign_grpid(group); #endif /* Duplicate the parent tasks environment */ diff --git a/sched/group/group_find.c b/sched/group/group_find.c index df61d7f406..301a3e4820 100644 --- a/sched/group/group_find.c +++ b/sched/group/group_find.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group_find.c * - * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016, 2019 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,6 +46,7 @@ #include #include +#include #include "group/group.h" #include "environ/environ.h" @@ -55,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: group_findbygid + * Name: group_findby_grpid * * Description: * Given a group ID, find the group task structure with that ID. IDs are @@ -64,7 +65,7 @@ * because if the group disappears, this function will fail gracefully. * * Input Parameters: - * gid - The group ID to find. + * grpid - The group ID to find. * * Returned Value: * On success, a pointer to the group task structure is returned. This @@ -79,7 +80,7 @@ ****************************************************************************/ #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) -FAR struct task_group_s *group_findbygid(gid_t gid) +FAR struct task_group_s *group_findby_grpid(grpid_t grpid) { FAR struct task_group_s *group; irqstate_t flags; @@ -89,7 +90,7 @@ FAR struct task_group_s *group_findbygid(gid_t gid) flags = enter_critical_section(); for (group = g_grouphead; group; group = group->flink) { - if (group->tg_gid == gid) + if (group->tg_grpid == grpid) { leave_critical_section(flags); return group; diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index 47f4d56292..57bf957226 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/group/group_leave.c * - * Copyright (C) 2013-2018 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2019 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -203,7 +203,7 @@ static inline void group_release(FAR struct task_group_s *group) /* Mark no address environment */ - g_gid_current = 0; + g_grpid_current = 0; #endif #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV) diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index 77a567be36..fa6676684f 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -231,7 +231,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) ctcb = sched_gettcb((pid_t)id); #ifdef HAVE_GROUP_MEMBERS - if (ctcb == NULL || ctcb->group->tg_pgid != rtcb->group->tg_gid) + if (ctcb == NULL || ctcb->group->tg_pgrpid != rtcb->group->tg_grpid) #else if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->pid) #endif @@ -274,7 +274,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) ctcb = sched_gettcb((pid_t)id); #ifdef HAVE_GROUP_MEMBERS - if (ctcb == NULL || ctcb->group->tg_pgid != rtcb->group->tg_gid) + if (ctcb == NULL || ctcb->group->tg_pgrpid != rtcb->group->tg_grpid) #else if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->pid) #endif diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index fa786a4e8d..f5fecafd38 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -7,7 +7,7 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions - * are met: + * are met:make * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. @@ -359,7 +359,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Make sure that the thread it is our child. */ #ifdef HAVE_GROUP_MEMBERS - if (ctcb->group->tg_pgid != rtcb->group->tg_gid) + if (ctcb->group->tg_pgrpid != rtcb->group->tg_grpid) #else if (ctcb->group->tg_ppid != rtcb->pid) #endif @@ -403,7 +403,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) ctcb = sched_gettcb(pid); #ifdef HAVE_GROUP_MEMBERS - if (ctcb == NULL || ctcb->group->tg_pgid != rtcb->group->tg_gid) + if (ctcb == NULL || ctcb->group->tg_pgrpid != rtcb->group->tg_grpid) #else if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->pid) #endif diff --git a/sched/task/task_exithook.c b/sched/task/task_exithook.c index b02a2e0d3a..5803109f41 100644 --- a/sched/task/task_exithook.c +++ b/sched/task/task_exithook.c @@ -298,7 +298,7 @@ static inline void nxtask_groupexit(FAR struct task_group_s *group) #ifdef CONFIG_SCHED_HAVE_PARENT #ifdef HAVE_GROUP_MEMBERS -static inline void nxtask_sigchild(gid_t pgid, FAR struct tcb_s *ctcb, +static inline void nxtask_sigchild(grpid_t pgrpid, FAR struct tcb_s *ctcb, int status) { FAR struct task_group_s *chgrp = ctcb->group; @@ -312,14 +312,14 @@ static inline void nxtask_sigchild(gid_t pgid, FAR struct tcb_s *ctcb, * this case, the child task group has been orphaned. */ - pgrp = group_findbygid(pgid); + pgrp = group_findby_grpid(pgrpid); if (!pgrp) { /* Set the task group ID to an invalid group ID. The dead parent * task group ID could get reused some time in the future. */ - chgrp->tg_pgid = INVALID_GROUP_ID; + chgrp->tg_pgrpid = INVALID_GROUP_ID; return; } @@ -449,7 +449,7 @@ static inline void nxtask_signalparent(FAR struct tcb_s *ctcb, int status) /* Send SIGCHLD to all members of the parent's task group */ - nxtask_sigchild(ctcb->group->tg_pgid, ctcb, status); + nxtask_sigchild(ctcb->group->tg_pgrpid, ctcb, status); sched_unlock(); #else FAR struct tcb_s *ptcb; diff --git a/sched/task/task_reparent.c b/sched/task/task_reparent.c index 45279a1a0b..d4411db1b4 100644 --- a/sched/task/task_reparent.c +++ b/sched/task/task_reparent.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task/task_reparent.c * - * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016, 2019 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,6 +42,7 @@ #include #include +#include #include "sched/sched.h" #include "group/group.h" @@ -79,8 +80,8 @@ int task_reparent(pid_t ppid, pid_t chpid) FAR struct task_group_s *ogrp; FAR struct task_group_s *pgrp; FAR struct tcb_s *tcb; - gid_t ogid; - gid_t pgid; + grpid_t ogrpid; + grpid_t pgrpid; irqstate_t flags; int ret; @@ -102,13 +103,13 @@ int task_reparent(pid_t ppid, pid_t chpid) DEBUGASSERT(tcb->group); chgrp = tcb->group; - /* Get the GID of the old parent task's task group (ogid) */ + /* Get the GID of the old parent task's task group (ogrpid) */ - ogid = chgrp->tg_pgid; + ogrpid = chgrp->tg_pgrpid; /* Get the old parent task's task group (ogrp) */ - ogrp = group_findbygid(ogid); + ogrp = group_findby_grpid(ogrpid); if (!ogrp) { ret = -ESRCH; @@ -124,8 +125,8 @@ int task_reparent(pid_t ppid, pid_t chpid) { /* Get the grandparent task's task group (pgrp) */ - pgid = ogrp->tg_pgid; - pgrp = group_findbygid(pgid); + pgrpid = ogrp->tg_pgrpid; + pgrp = group_findby_grpid(pgrpid); } else { @@ -139,7 +140,7 @@ int task_reparent(pid_t ppid, pid_t chpid) } pgrp = tcb->group; - pgid = pgrp->tg_gid; + pgrpid = pgrp->tg_grpid; } if (!pgrp) @@ -153,7 +154,7 @@ int task_reparent(pid_t ppid, pid_t chpid) * all members of the child's task group. */ - chgrp->tg_pgid = pgid; + chgrp->tg_pgrpid = pgrpid; #ifdef CONFIG_SCHED_CHILD_STATUS /* Remove the child status entry from old parent task group */ diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index 2089917018..ff1e1cab28 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -228,7 +228,7 @@ static inline void nxtask_saveparent(FAR struct tcb_s *tcb, uint8_t ttype) * child's task group. */ - tcb->group->tg_pgid = rtcb->group->tg_gid; + tcb->group->tg_pgrpid = rtcb->group->tg_grpid; #else /* Save the parent task's ID in the child task's group. */