Changeset 1910


Ignore:
Timestamp:
Apr 25, 2005, 5:58:57 AM (20 years ago)
Author:
bird
Message:

Implemented (not tested) process priority manangement.

Location:
trunk/src/emx
Files:
7 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/ChangeLog.LIBC

    • Property cvs2svn:cvs-rev changed from 1.32 to 1.33
    r1909 r1910  
    11/* $Id$ */
     2
     32005-04-24: knut st. osmundsen <bird-gccos2-spam@anduin.net>
     4    - libc:
     5        o Fixed bug in getfsstate(). (df from coreutils works now!)
     6        o Implemented process priority management. Added nice(), setpriority()
     7          and getpriority() in the process.
     8        o Added process enumeration and access function to sharedpm.
    29
    3102005-04-23: knut st. osmundsen <bird-gccos2-spam@anduin.net>
  • trunk/src/emx/include/InnoTekLIBC/backend.h

    • Property cvs2svn:cvs-rev changed from 1.18 to 1.19
    r1909 r1910  
    789789int __libc_Back_processSetGidAll(gid_t rgid, gid_t egid, gid_t svgid);
    790790
     791/**
     792 * Gets the most favourable priority of a process, group of processes
     793 * or all processed owned by a user.
     794 *
     795 * @returns 0 on success.
     796 * @returns Negative error code (errno.h) on failure.
     797 * @param   iWhich      PRIO_PROCESS, PRIO_PGRP, or PRIO_USER.
     798 * @param   idWho       Id of the type specified by iWhich. 0 means the current process/pgrp/user.
     799 * @param   piPrio      Where to store the priority.
     800 */
     801int __libc_Back_processGetPriority(int iWhich, id_t idWho, int *piPrio);
     802
     803/**
     804 * Sets the priority of a process, a group of processes
     805 * or all processed owned by a user.
     806 *
     807 * @returns 0 on success.
     808 * @returns Negative error code (errno.h) on failure.
     809 * @param   iWhich      PRIO_PROCESS, PRIO_PGRP, or PRIO_USER.
     810 * @param   idWho       Id of the type specified by iWhich. 0 means the current process/pgrp/user.
     811 * @param   iPrio       The new priority.
     812 */
     813int __libc_Back_processSetPriority(int iWhich, id_t idWho, int iPrio);
     814
    791815
    792816/** @} */
  • trunk/src/emx/include/InnoTekLIBC/sharedpm.h

    • Property cvs2svn:cvs-rev changed from 1.19 to 1.20
    r1909 r1910  
    316316    /** User & Group
    317317     * @{ */
    318     /** 28 - User id. */
     318    /** 28 - User id (also called Real User id). */
    319319    uid_t                       uid;
    320320    /** 32 - Effective user id. */
     
    322322    /** 36 - Saved user id. */
    323323    uid_t                       svuid;
    324     /** 40 - Group id. */
     324    /** 40 - Group id (also called Real Group id). */
    325325    gid_t                       gid;
    326326    /** 44 - Effecive group id. */
     
    392392    /** @} */
    393393
    394     /** 180 - Per Process Sockets Reference Counters. */
     394    /** 180 - Per Process Sockets Reference Counters. (Data is process local.) */
    395395    uint16_t                   *pacTcpipRefs;
    396 
    397     /** 184 - Reserved pool pointer field with default value 0. */
    398     unsigned                    auReserved[56 - 46];
    399 
    400 
    401     /** 224 - Number of possible pointers to shared memory starting at pvInherit.
     396    /** 184 - The Process priority (unix). */
     397    int                         iNice;
     398    /** 188 - Reserved fields with default value 0. */
     399    unsigned                    auReserved[56 - 47];
     400
     401
     402    /** 224 - Number of possible pointers to shared memory starting at pInherit.
    402403     * This means we can extend the structure with pointers for as long as we
    403404     * want and still have older LIBC versions cleanup the mess. */
     
    645646
    646647/**
     648 * Process enumeration callback function.
     649 *
     650 * @returns 0 to continue the enumeration.
     651 * @returns Non-zero to stop the enumeration. The enumeration
     652 *          api will return this same value.
     653 *
     654 * @param   pProcess    The current process.
     655 * @param   pvUser      The user argument.
     656 * @remark  It is *not* allowed to terminate the thread or process, do long jumps
     657 *          or anything else which causes the enumeration function not to release
     658 *          the lock.
     659 *          It is not allowed to do expensive stuff either as it will harm other
     660 *          processes in the system which want to access the shared process facility!
     661 */
     662typedef int __LIBC_FNSPNENUM(__LIBC_PSPMPROCESS pProcess, void *pvUser);
     663/** Pointer to an process enumeration callback function. */
     664typedef __LIBC_FNSPNENUM *__LIBC_PFNSPNENUM;
     665
     666/**
     667 * Enumerates all alive processes in a group.
     668 *
     669 * @returns 0 on success.
     670 * @returns -ESRCH if the process group wasn't found.
     671 * @returns -EINVAL if pgrp is negative.
     672 * @returns Whatever non-zero value the pfnCallback function returns to stop the enumeration.
     673 *
     674 * @param   pgrp            The process group id. 0 is an alias for the process group the caller belongs to.
     675 * @param   pfnCallback     Callback function.
     676 * @param   pvUser          User argument to the callback.
     677 */
     678int __libc_spmEnumProcessesByPGrp(pid_t pgrp, __LIBC_PFNSPNENUM pfnCallback, void *pvUser);
     679
     680/**
     681 * Enumerates all alive processes owned by a user.
     682 *
     683 * @returns 0 on success.
     684 * @returns -ESRCH if the process group wasn't found.
     685 * @returns -EINVAL if uid is negative.
     686 * @returns Whatever non-zero value the pfnCallback function returns to stop the enumeration.
     687 *
     688 * @param   uid             The process user id.
     689 * @param   pfnCallback     Callback function.
     690 * @param   pvUser          User argument to the callback.
     691 */
     692int __libc_spmEnumProcessesByUser(uid_t uid, __LIBC_PFNSPNENUM pfnCallback, void *pvUser);
     693
     694/**
    647695 * Release reference to the given process.
    648696 *
     
    652700 */
    653701int __libc_spmRelease(__LIBC_PSPMPROCESS pProcess);
     702
     703/**
     704 * Checks if the calling process can see the specfied one.
     705 *
     706 * @returns 0 if it can see it.
     707 * @returns -ESRCH (or other approriate error code) if it cannot.
     708 *
     709 * @param   pProcess    The process in question.
     710 */
     711int __libc_spmCanSee(__LIBC_PSPMPROCESS pProcess);
     712
     713/**
     714 * Checks if we are a system-wide super user.
     715 *
     716 * @returns 0 if we are.
     717 * @returns -EPERM if we aren't.
     718 */
     719int __libc_spmIsSuperUser(void);
     720
     721/**
     722 * Checks if the caller can modify the specified process.
     723 *
     724 * @returns 0 if we can modify it.
     725 * @returns -EPERM if we cannot modify it.
     726 * @param   pProcess    The process in question.
     727 */
     728int __libc_spmCanModify(__LIBC_PSPMPROCESS pProcess);
    654729
    655730/**
     
    691766 * Identificators which can be obtained using __libc_spmGetId().
    692767 */
    693 typedef enum __LIBC_SPMId
     768typedef enum __LIBC_SPMID
    694769{
    695770    __LIBC_SPMID_PID = 0,
  • trunk/src/emx/include/sys/resource.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1909 r1910  
    3737/** @file
    3838 * FreeBSD 5.1
     39 * @changed bird: get/setpriority takes id_t not int according to SuS.
    3940 */
    4041
     
    156157
    157158__BEGIN_DECLS
    158 int     getpriority(int, int);
     159int     getpriority(int, /*int*/ id_t);         /* bird: SuS uses id_t */
    159160int     getrlimit(int, struct rlimit *);
    160161int     getrusage(int, struct rusage *);
    161 int     setpriority(int, int, int);
     162int     setpriority(int, /*int*/ id_t, int);    /* bird: SuS uses id_t */
    162163int     setrlimit(int, const struct rlimit *);
    163164__END_DECLS
  • trunk/src/emx/include/unistd.h

    • Property cvs2svn:cvs-rev changed from 1.27 to 1.28
    r1909 r1910  
    448448int      lchown(const char *, uid_t, gid_t);
    449449int      lockf(int, int, off_t);
    450 /** @todo int    nice(int); */
     450int      nice(int);
    451451ssize_t  pread(int, void *, size_t, off_t);
    452452ssize_t  pwrite(int, const void *, size_t, off_t);
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.102 to 1.103
    r1909 r1910  
    14951495    "__nl_explode_name" @1501
    14961496    "__nl_normalize_codeset" @1502
     1497    ; april coding continues...
    14971498    "___fbufsize" @1503
    14981499    "___fpending" @1504
     1500    "___libc_Back_processGetPriority" @1505
     1501    "___libc_Back_processSetPriority" @1506
     1502    "__std_getpriority" @1507
     1503    "__std_setpriority" @1508
     1504    "__std_nice" @1509
  • trunk/src/emx/src/lib/sys/sharedpm.c

    • Property cvs2svn:cvs-rev changed from 1.27 to 1.28
    r1909 r1910  
    612612     * Validate input.
    613613     */
    614     if (pid <= 0)
     614    if (pid < 0)
    615615    {
    616616        errno = EINVAL;
    617617        LIBCLOG_RETURN_P(NULL);
    618618    }
     619
     620    /*
     621     * Fast path for our selves.
     622     */
     623    if (!pid || gpSPMSelf->pid == pid)
     624        LIBCLOG_RETURN_P(gpSPMSelf);
    619625
    620626    /*
     
    665671     * Validate input.
    666672     */
    667     if (enmState >= __LIBC_PROCSTATE_MAX || pid <= 0)
     673    if (enmState >= __LIBC_PROCSTATE_MAX || pid < 0)
    668674    {
    669675        errno = EINVAL;
     
    672678
    673679    /*
     680     * Fast path for our selves.
     681     */
     682    if (!pid || gpSPMSelf->pid == pid)
     683        LIBCLOG_RETURN_P(gpSPMSelf->enmState == enmState ? gpSPMSelf : NULL);
     684
     685    /*
    674686     * Request mutex.
    675687     */
     
    694706    spmReleaseMutex(&RegRec);
    695707    LIBCLOG_RETURN_P(pProcess);
     708}
     709
     710
     711/**
     712 * Enumerates all alive processes in a group.
     713 *
     714 * @returns 0 on success.
     715 * @returns -ESRCH if the process group wasn't found.
     716 * @returns -EINVAL if pgrp is negative.
     717 * @returns Whatever non-zero value the pfnCallback function returns to stop the enumeration.
     718 *
     719 * @param   pgrp            The process group id. 0 is an alias for the process group the caller belongs to.
     720 * @param   pfnCallback     Callback function.
     721 * @param   pvUser          User argument to the callback.
     722 */
     723int __libc_spmEnumProcessesByPGrp(pid_t pgrp, __LIBC_PFNSPNENUM pfnCallback, void *pvUser)
     724{
     725    LIBCLOG_ENTER("pgrp=%d pfnCallback=%p pvUser=%p\n", pgrp, (void *)pfnCallback, pvUser);
     726    __LIBC_SPMXCPTREGREC    RegRec;
     727    __LIBC_PSPMPROCESS      pProcess;
     728    int                     rc;
     729
     730    /*
     731     * Validate input.
     732     */
     733    if (pgrp < 0)
     734        LIBCLOG_RETURN_P(-EINVAL);
     735
     736    /*
     737     * Request mutex.
     738     */
     739    rc = spmRequestMutex(&RegRec);
     740    if (rc)
     741        LIBCLOG_RETURN_P(rc);
     742
     743    /* resolve self reference. */
     744    if (!pgrp)
     745        pgrp = gpSPMSelf->pgrp;
     746
     747    /*
     748     * Enumerate the processes.
     749     */
     750    rc = -ESRCH;
     751    for (pProcess = gpSPMHdr->apHeads[__LIBC_PROCSTATE_ALIVE]; pProcess ; pProcess = pProcess->pNext)
     752    {
     753        if (    pProcess->pgrp == pgrp
     754            &&  pProcess->enmState == __LIBC_PROCSTATE_ALIVE)
     755        {
     756            pProcess->cReferences++;
     757            rc = pfnCallback(pProcess, pvUser);
     758            pProcess->cReferences--;
     759            if (rc)
     760                break;
     761        }
     762    }
     763
     764    /*
     765     * Release mutex and return.
     766     */
     767    spmReleaseMutex(&RegRec);
     768    LIBCLOG_RETURN_P(rc);
     769}
     770
     771
     772/**
     773 * Enumerates all alive processes owned by a user.
     774 *
     775 * @returns 0 on success.
     776 * @returns -ESRCH if the process group wasn't found.
     777 * @returns -EINVAL if uid is negative.
     778 * @returns Whatever non-zero value the pfnCallback function returns to stop the enumeration.
     779 *
     780 * @param   uid             The process user id.
     781 * @param   pfnCallback     Callback function.
     782 * @param   pvUser          User argument to the callback.
     783 */
     784int __libc_spmEnumProcessesByUser(uid_t uid, __LIBC_PFNSPNENUM pfnCallback, void *pvUser)
     785{
     786    LIBCLOG_ENTER("uid=%d pfnCallback=%p pvUser=%p\n", uid, (void *)pfnCallback, pvUser);
     787    __LIBC_SPMXCPTREGREC    RegRec;
     788    __LIBC_PSPMPROCESS      pProcess;
     789    int                     rc;
     790
     791    /*
     792     * Validate input.
     793     */
     794    if (uid < 0)
     795        LIBCLOG_RETURN_P(-EINVAL);
     796
     797    /*
     798     * Request mutex.
     799     */
     800    rc = spmRequestMutex(&RegRec);
     801    if (rc)
     802        LIBCLOG_RETURN_P(rc);
     803
     804    /*
     805     * Enumerate the processes.
     806     */
     807    rc = -ESRCH;
     808    for (pProcess = gpSPMHdr->apHeads[__LIBC_PROCSTATE_ALIVE]; pProcess ; pProcess = pProcess->pNext)
     809    {
     810        if (    pProcess->euid == uid
     811            &&  pProcess->enmState == __LIBC_PROCSTATE_ALIVE)
     812        {
     813            pProcess->cReferences++;
     814            rc = pfnCallback(pProcess, pvUser);
     815            pProcess->cReferences--;
     816            if (rc)
     817                break;
     818        }
     819    }
     820
     821    /*
     822     * Release mutex and return.
     823     */
     824    spmReleaseMutex(&RegRec);
     825    LIBCLOG_RETURN_P(rc);
    696826}
    697827
     
    742872    spmReleaseMutex(&RegRec);
    743873    LIBCLOG_RETURN_INT(0);
     874}
     875
     876
     877/**
     878 * Checks if the calling process can see the specfied one.
     879 *
     880 * @returns 0 if it can see it.
     881 * @returns -ESRCH (or other approriate error code) if it cannot.
     882 *
     883 * @param   pProcess    The process in question.
     884 */
     885int __libc_spmCanSee(__LIBC_PSPMPROCESS pProcess)
     886{
     887    return 0;
     888}
     889
     890
     891/**
     892 * Checks if we are a system-wide super user.
     893 *
     894 * @returns 0 if we are.
     895 * @returns -EPERM if we aren't.
     896 */
     897int __libc_spmIsSuperUser(void)
     898{
     899    if (gpSPMSelf->euid == 0)
     900        return 0;
     901    return -EPERM;
     902}
     903
     904
     905/**
     906 * Checks if the caller can modify the specified process.
     907 *
     908 * @returns 0 if we can modify it.
     909 * @returns -EPERM if we cannot modify it.
     910 * @param   pProcess    The process in question.
     911 */
     912int __libc_spmCanModify(__LIBC_PSPMPROCESS pProcess)
     913{
     914    if (!gpSPMSelf->euid)
     915        return 0;
     916    uid_t euid = pProcess->euid;
     917    if (    euid == gpSPMSelf->euid
     918        ||  euid == gpSPMSelf->uid)
     919        return 0;
     920    return -EPERM;
    744921}
    745922
Note: See TracChangeset for help on using the changeset viewer.