root/kernel/sys.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_ni_syscall
  2. sys_idle
  3. proc_sel
  4. sys_setpriority
  5. sys_getpriority
  6. sys_profil
  7. sys_ftime
  8. sys_break
  9. sys_stty
  10. sys_gtty
  11. sys_prof
  12. sys_reboot
  13. ctrl_alt_del
  14. sys_setregid
  15. sys_setgid
  16. sys_acct
  17. sys_phys
  18. sys_lock
  19. sys_mpx
  20. sys_ulimit
  21. sys_old_syscall
  22. sys_setreuid
  23. sys_setuid
  24. sys_times
  25. sys_brk
  26. sys_setpgid
  27. sys_getpgid
  28. sys_getpgrp
  29. sys_setsid
  30. sys_getgroups
  31. sys_setgroups
  32. in_group_p
  33. sys_newuname
  34. sys_uname
  35. sys_olduname
  36. sys_sethostname
  37. sys_setdomainname
  38. sys_getrlimit
  39. sys_setrlimit
  40. getrusage
  41. sys_getrusage
  42. sys_umask

   1 /*
   2  *  linux/kernel/sys.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 #include <linux/config.h>
   8 #include <linux/errno.h>
   9 #include <linux/sched.h>
  10 #include <linux/kernel.h>
  11 #include <linux/times.h>
  12 #include <linux/utsname.h>
  13 #include <linux/param.h>
  14 #include <linux/resource.h>
  15 #include <linux/signal.h>
  16 #include <linux/string.h>
  17 #include <linux/ptrace.h>
  18 #include <linux/stat.h>
  19 #include <linux/mman.h>
  20 
  21 #include <asm/segment.h>
  22 #include <asm/io.h>
  23 
  24 /*
  25  * this indicates wether you can reboot with ctrl-alt-del: the default is yes
  26  */
  27 static int C_A_D = 1;
  28 
  29 extern void adjust_clock(void);
  30 
  31 #define PZERO   15
  32 
  33 asmlinkage int sys_ni_syscall(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35         return -EINVAL;
  36 }
  37 
  38 asmlinkage int sys_idle(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  39 {
  40         int i;
  41 
  42         if (current->pid != 0)
  43                 return -EPERM;
  44 
  45         /* Map out the low memory: it's no longer needed */
  46         for (i = 0 ; i < 768 ; i++)
  47                 swapper_pg_dir[i] = 0;
  48 
  49         /* endless idle loop with no priority at all */
  50         current->counter = -100;
  51         for (;;) {
  52                 if (!need_resched)
  53                         __asm__("hlt");
  54                 schedule();
  55         }
  56 }
  57 
  58 static int proc_sel(struct task_struct *p, int which, int who)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60         switch (which) {
  61                 case PRIO_PROCESS:
  62                         if (!who && p == current)
  63                                 return 1;
  64                         return(p->pid == who);
  65                 case PRIO_PGRP:
  66                         if (!who)
  67                                 who = current->pgrp;
  68                         return(p->pgrp == who);
  69                 case PRIO_USER:
  70                         if (!who)
  71                                 who = current->uid;
  72                         return(p->uid == who);
  73         }
  74         return 0;
  75 }
  76 
  77 asmlinkage int sys_setpriority(int which, int who, int niceval)
     /* [previous][next][first][last][top][bottom][index][help] */
  78 {
  79         struct task_struct **p;
  80         int error = ESRCH;
  81         int priority;
  82 
  83         if (which > 2 || which < 0)
  84                 return -EINVAL;
  85 
  86         if ((priority = PZERO - niceval) <= 0)
  87                 priority = 1;
  88 
  89         for(p = &LAST_TASK; p > &FIRST_TASK; --p) {
  90                 if (!*p || !proc_sel(*p, which, who))
  91                         continue;
  92                 if ((*p)->uid != current->euid &&
  93                         (*p)->uid != current->uid && !suser()) {
  94                         error = EPERM;
  95                         continue;
  96                 }
  97                 if (error == ESRCH)
  98                         error = 0;
  99                 if (priority > (*p)->priority && !suser())
 100                         error = EACCES;
 101                 else
 102                         (*p)->priority = priority;
 103         }
 104         return -error;
 105 }
 106 
 107 asmlinkage int sys_getpriority(int which, int who)
     /* [previous][next][first][last][top][bottom][index][help] */
 108 {
 109         struct task_struct **p;
 110         int max_prio = 0;
 111 
 112         if (which > 2 || which < 0)
 113                 return -EINVAL;
 114 
 115         for(p = &LAST_TASK; p > &FIRST_TASK; --p) {
 116                 if (!*p || !proc_sel(*p, which, who))
 117                         continue;
 118                 if ((*p)->priority > max_prio)
 119                         max_prio = (*p)->priority;
 120         }
 121         return(max_prio ? max_prio : -ESRCH);
 122 }
 123 
 124 asmlinkage int sys_profil(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 125 {
 126         return -ENOSYS;
 127 }
 128 
 129 asmlinkage int sys_ftime(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 130 {
 131         return -ENOSYS;
 132 }
 133 
 134 asmlinkage int sys_break(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 135 {
 136         return -ENOSYS;
 137 }
 138 
 139 asmlinkage int sys_stty(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 140 {
 141         return -ENOSYS;
 142 }
 143 
 144 asmlinkage int sys_gtty(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 145 {
 146         return -ENOSYS;
 147 }
 148 
 149 asmlinkage int sys_prof(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 150 {
 151         return -ENOSYS;
 152 }
 153 
 154 extern void hard_reset_now(void);
 155 
 156 /*
 157  * Reboot system call: for obvious reasons only root may call it,
 158  * and even root needs to set up some magic numbers in the registers
 159  * so that some mistake won't make this reboot the whole machine.
 160  * You can also set the meaning of the ctrl-alt-del-key here.
 161  *
 162  * reboot doesn't sync: do that yourself before calling this.
 163  */
 164 asmlinkage int sys_reboot(int magic, int magic_too, int flag)
     /* [previous][next][first][last][top][bottom][index][help] */
 165 {
 166         if (!suser())
 167                 return -EPERM;
 168         if (magic != 0xfee1dead || magic_too != 672274793)
 169                 return -EINVAL;
 170         if (flag == 0x01234567)
 171                 hard_reset_now();
 172         else if (flag == 0x89ABCDEF)
 173                 C_A_D = 1;
 174         else if (!flag)
 175                 C_A_D = 0;
 176         else
 177                 return -EINVAL;
 178         return (0);
 179 }
 180 
 181 /*
 182  * This function gets called by ctrl-alt-del - ie the keyboard interrupt.
 183  * As it's called within an interrupt, it may NOT sync: the only choice
 184  * is wether to reboot at once, or just ignore the ctrl-alt-del.
 185  */
 186 void ctrl_alt_del(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 187 {
 188         if (C_A_D)
 189                 hard_reset_now();
 190         else
 191                 send_sig(SIGINT,task[1],1);
 192 }
 193         
 194 
 195 /*
 196  * Unprivileged users may change the real gid to the effective gid
 197  * or vice versa.  (BSD-style)
 198  *
 199  * If you set the real gid at all, or set the effective gid to a value not
 200  * equal to the real gid, then the saved gid is set to the new effective gid.
 201  *
 202  * This makes it possible for a setgid program to completely drop its
 203  * privileges, which is often a useful assertion to make when you are doing
 204  * a security audit over a program.
 205  *
 206  * The general idea is that a program which uses just setregid() will be
 207  * 100% compatible with BSD.  A program which uses just setgid() will be
 208  * 100% compatible with POSIX w/ Saved ID's. 
 209  */
 210 asmlinkage int sys_setregid(gid_t rgid, gid_t egid)
     /* [previous][next][first][last][top][bottom][index][help] */
 211 {
 212         int old_rgid = current->gid;
 213 
 214         if (rgid != (gid_t) -1) {
 215                 if ((current->egid==rgid) ||
 216                     (old_rgid == rgid) || 
 217                     suser())
 218                         current->gid = rgid;
 219                 else
 220                         return(-EPERM);
 221         }
 222         if (egid != (gid_t) -1) {
 223                 if ((old_rgid == egid) ||
 224                     (current->egid == egid) ||
 225                     suser())
 226                         current->egid = egid;
 227                 else {
 228                         current->gid = old_rgid;
 229                         return(-EPERM);
 230                 }
 231         }
 232         if (rgid != (gid_t) -1 ||
 233             (egid != (gid_t) -1 && egid != old_rgid))
 234                 current->sgid = current->egid;
 235         return 0;
 236 }
 237 
 238 /*
 239  * setgid() is implemeneted like SysV w/ SAVED_IDS 
 240  */
 241 asmlinkage int sys_setgid(gid_t gid)
     /* [previous][next][first][last][top][bottom][index][help] */
 242 {
 243         if (suser())
 244                 current->gid = current->egid = current->sgid = gid;
 245         else if ((gid == current->gid) || (gid == current->sgid))
 246                 current->egid = gid;
 247         else
 248                 return -EPERM;
 249         return 0;
 250 }
 251 
 252 asmlinkage int sys_acct(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 253 {
 254         return -ENOSYS;
 255 }
 256 
 257 asmlinkage int sys_phys(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 258 {
 259         return -ENOSYS;
 260 }
 261 
 262 asmlinkage int sys_lock(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 263 {
 264         return -ENOSYS;
 265 }
 266 
 267 asmlinkage int sys_mpx(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 268 {
 269         return -ENOSYS;
 270 }
 271 
 272 asmlinkage int sys_ulimit(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 273 {
 274         return -ENOSYS;
 275 }
 276 
 277 asmlinkage int sys_old_syscall(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 278 {
 279         return -ENOSYS;
 280 }
 281 
 282 /*
 283  * Unprivileged users may change the real uid to the effective uid
 284  * or vice versa.  (BSD-style)
 285  *
 286  * If you set the real uid at all, or set the effective uid to a value not
 287  * equal to the real uid, then the saved uid is set to the new effective uid.
 288  *
 289  * This makes it possible for a setuid program to completely drop its
 290  * privileges, which is often a useful assertion to make when you are doing
 291  * a security audit over a program.
 292  *
 293  * The general idea is that a program which uses just setreuid() will be
 294  * 100% compatible with BSD.  A program which uses just setuid() will be
 295  * 100% compatible with POSIX w/ Saved ID's. 
 296  */
 297 asmlinkage int sys_setreuid(uid_t ruid, uid_t euid)
     /* [previous][next][first][last][top][bottom][index][help] */
 298 {
 299         int old_ruid = current->uid;
 300 
 301         if (ruid != (uid_t) -1) {
 302                 if ((old_ruid == ruid) || 
 303                     (current->euid==ruid) ||
 304                     suser())
 305                         current->uid = ruid;
 306                 else
 307                         return(-EPERM);
 308         }
 309         if (euid != (uid_t) -1) {
 310                 if ((old_ruid == euid) ||
 311                     (current->euid == euid) ||
 312                     (current->suid == euid) ||
 313                     suser())
 314                         current->euid = euid;
 315                 else {
 316                         current->uid = old_ruid;
 317                         return(-EPERM);
 318                 }
 319         }
 320         if (ruid != (uid_t) -1 ||
 321             (euid != (uid_t) -1 && euid != old_ruid))
 322                 current->suid = current->euid;
 323         return 0;
 324 }
 325 
 326 /*
 327  * setuid() is implemeneted like SysV w/ SAVED_IDS 
 328  * 
 329  * Note that SAVED_ID's is deficient in that a setuid root program
 330  * like sendmail, for example, cannot set its uid to be a normal 
 331  * user and then switch back, because if you're root, setuid() sets
 332  * the saved uid too.  If you don't like this, blame the bright people
 333  * in the POSIX commmittee and/or USG.  Note that the BSD-style setreuid()
 334  * will allow a root program to temporarily drop privileges and be able to
 335  * regain them by swapping the real and effective uid.  
 336  */
 337 asmlinkage int sys_setuid(uid_t uid)
     /* [previous][next][first][last][top][bottom][index][help] */
 338 {
 339         if (suser())
 340                 current->uid = current->euid = current->suid = uid;
 341         else if ((uid == current->uid) || (uid == current->suid))
 342                 current->euid = uid;
 343         else
 344                 return -EPERM;
 345         return(0);
 346 }
 347 
 348 asmlinkage int sys_times(struct tms * tbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
 349 {
 350         if (tbuf) {
 351                 int error = verify_area(VERIFY_WRITE,tbuf,sizeof *tbuf);
 352                 if (error)
 353                         return error;
 354                 put_fs_long(current->utime,(unsigned long *)&tbuf->tms_utime);
 355                 put_fs_long(current->stime,(unsigned long *)&tbuf->tms_stime);
 356                 put_fs_long(current->cutime,(unsigned long *)&tbuf->tms_cutime);
 357                 put_fs_long(current->cstime,(unsigned long *)&tbuf->tms_cstime);
 358         }
 359         return jiffies;
 360 }
 361 
 362 asmlinkage int sys_brk(unsigned long brk)
     /* [previous][next][first][last][top][bottom][index][help] */
 363 {
 364         int freepages;
 365         unsigned long rlim;
 366         unsigned long newbrk, oldbrk;
 367 
 368         if (brk < current->mm->end_code)
 369                 return current->mm->brk;
 370         newbrk = PAGE_ALIGN(brk);
 371         oldbrk = PAGE_ALIGN(current->mm->brk);
 372         if (oldbrk == newbrk)
 373                 return current->mm->brk = brk;
 374 
 375         /*
 376          * Always allow shrinking brk
 377          */
 378         if (brk <= current->mm->brk) {
 379                 current->mm->brk = brk;
 380                 do_munmap(newbrk, oldbrk-newbrk);
 381                 return brk;
 382         }
 383         /*
 384          * Check against rlimit and stack..
 385          */
 386         rlim = current->rlim[RLIMIT_DATA].rlim_cur;
 387         if (rlim >= RLIM_INFINITY)
 388                 rlim = ~0;
 389         if (brk - current->mm->end_code > rlim ||
 390             brk >= current->mm->start_stack - 16384)
 391                 return current->mm->brk;
 392         /*
 393          * stupid algorithm to decide if we have enough memory: while
 394          * simple, it hopefully works in most obvious cases.. Easy to
 395          * fool it, but this should catch most mistakes.
 396          */
 397         freepages = buffermem >> 12;
 398         freepages += nr_free_pages;
 399         freepages += nr_swap_pages;
 400         freepages -= (high_memory - 0x100000) >> 16;
 401         freepages -= (newbrk-oldbrk) >> 12;
 402         if (freepages < 0)
 403                 return current->mm->brk;
 404 #if 0
 405         freepages += current->mm->rss;
 406         freepages -= oldbrk >> 12;
 407         if (freepages < 0)
 408                 return current->mm->brk;
 409 #endif
 410         /*
 411          * Ok, we have probably got enough memory - let it rip.
 412          */
 413         current->mm->brk = brk;
 414         do_mmap(NULL, oldbrk, newbrk-oldbrk,
 415                 PROT_READ|PROT_WRITE|PROT_EXEC,
 416                 MAP_FIXED|MAP_PRIVATE, 0);
 417         return brk;
 418 }
 419 
 420 /*
 421  * This needs some heave checking ...
 422  * I just haven't get the stomach for it. I also don't fully
 423  * understand sessions/pgrp etc. Let somebody who does explain it.
 424  *
 425  * OK, I think I have the protection semantics right.... this is really
 426  * only important on a multi-user system anyway, to make sure one user
 427  * can't send a signal to a process owned by another.  -TYT, 12/12/91
 428  *
 429  * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
 430  * LBT 04.03.94
 431  */
 432 asmlinkage int sys_setpgid(pid_t pid, pid_t pgid)
     /* [previous][next][first][last][top][bottom][index][help] */
 433 {
 434         struct task_struct * p;
 435 
 436         if (!pid)
 437                 pid = current->pid;
 438         if (!pgid)
 439                 pgid = pid;
 440         if (pgid < 0)
 441                 return -EINVAL;
 442         for_each_task(p) {
 443                 if (p->pid == pid)
 444                         goto found_task;
 445         }
 446         return -ESRCH;
 447 
 448 found_task:
 449         if (p->p_pptr == current || p->p_opptr == current) {
 450                 if (p->session != current->session)
 451                         return -EPERM;
 452                 if (p->did_exec)
 453                         return -EACCES;
 454         } else if (p != current)
 455                 return -ESRCH;
 456         if (p->leader)
 457                 return -EPERM;
 458         if (pgid != pid) {
 459                 struct task_struct * tmp;
 460                 for_each_task (tmp) {
 461                         if (tmp->pgrp == pgid &&
 462                          tmp->session == current->session)
 463                                 goto ok_pgid;
 464                 }
 465                 return -EPERM;
 466         }
 467 
 468 ok_pgid:
 469         p->pgrp = pgid;
 470         return 0;
 471 }
 472 
 473 asmlinkage int sys_getpgid(pid_t pid)
     /* [previous][next][first][last][top][bottom][index][help] */
 474 {
 475         struct task_struct * p;
 476 
 477         if (!pid)
 478                 return current->pgrp;
 479         for_each_task(p) {
 480                 if (p->pid == pid)
 481                         return p->pgrp;
 482         }
 483         return -ESRCH;
 484 }
 485 
 486 asmlinkage int sys_getpgrp(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 487 {
 488         return current->pgrp;
 489 }
 490 
 491 asmlinkage int sys_setsid(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 492 {
 493         if (current->leader)
 494                 return -EPERM;
 495         current->leader = 1;
 496         current->session = current->pgrp = current->pid;
 497         current->tty = NULL;
 498         return current->pgrp;
 499 }
 500 
 501 /*
 502  * Supplementary group ID's
 503  */
 504 asmlinkage int sys_getgroups(int gidsetsize, gid_t *grouplist)
     /* [previous][next][first][last][top][bottom][index][help] */
 505 {
 506         int i;
 507 
 508         if (gidsetsize) {
 509                 i = verify_area(VERIFY_WRITE, grouplist, sizeof(gid_t) * gidsetsize);
 510                 if (i)
 511                         return i;
 512         }
 513         for (i = 0 ; (i < NGROUPS) && (current->groups[i] != NOGROUP) ; i++) {
 514                 if (!gidsetsize)
 515                         continue;
 516                 if (i >= gidsetsize)
 517                         break;
 518                 put_fs_word(current->groups[i], (short *) grouplist);
 519                 grouplist++;
 520         }
 521         return(i);
 522 }
 523 
 524 asmlinkage int sys_setgroups(int gidsetsize, gid_t *grouplist)
     /* [previous][next][first][last][top][bottom][index][help] */
 525 {
 526         int     i;
 527 
 528         if (!suser())
 529                 return -EPERM;
 530         if (gidsetsize > NGROUPS)
 531                 return -EINVAL;
 532         for (i = 0; i < gidsetsize; i++, grouplist++) {
 533                 current->groups[i] = get_fs_word((unsigned short *) grouplist);
 534         }
 535         if (i < NGROUPS)
 536                 current->groups[i] = NOGROUP;
 537         return 0;
 538 }
 539 
 540 int in_group_p(gid_t grp)
     /* [previous][next][first][last][top][bottom][index][help] */
 541 {
 542         int     i;
 543 
 544         if (grp == current->egid)
 545                 return 1;
 546 
 547         for (i = 0; i < NGROUPS; i++) {
 548                 if (current->groups[i] == NOGROUP)
 549                         break;
 550                 if (current->groups[i] == grp)
 551                         return 1;
 552         }
 553         return 0;
 554 }
 555 
 556 asmlinkage int sys_newuname(struct new_utsname * name)
     /* [previous][next][first][last][top][bottom][index][help] */
 557 {
 558         int error;
 559 
 560         if (!name)
 561                 return -EFAULT;
 562         error = verify_area(VERIFY_WRITE, name, sizeof *name);
 563         if (!error)
 564                 memcpy_tofs(name,&system_utsname,sizeof *name);
 565         return error;
 566 }
 567 
 568 asmlinkage int sys_uname(struct old_utsname * name)
     /* [previous][next][first][last][top][bottom][index][help] */
 569 {
 570         int error;
 571         if (!name)
 572                 return -EFAULT;
 573         error = verify_area(VERIFY_WRITE, name,sizeof *name);
 574         if (error)
 575                 return error;
 576         memcpy_tofs(&name->sysname,&system_utsname.sysname,
 577                 sizeof (system_utsname.sysname));
 578         memcpy_tofs(&name->nodename,&system_utsname.nodename,
 579                 sizeof (system_utsname.nodename));
 580         memcpy_tofs(&name->release,&system_utsname.release,
 581                 sizeof (system_utsname.release));
 582         memcpy_tofs(&name->version,&system_utsname.version,
 583                 sizeof (system_utsname.version));
 584         memcpy_tofs(&name->machine,&system_utsname.machine,
 585                 sizeof (system_utsname.machine));
 586         return 0;
 587 }
 588 
 589 asmlinkage int sys_olduname(struct oldold_utsname * name)
     /* [previous][next][first][last][top][bottom][index][help] */
 590 {
 591         int error;
 592         if (!name)
 593                 return -EFAULT;
 594         error = verify_area(VERIFY_WRITE, name,sizeof *name);
 595         if (error)
 596                 return error;
 597         memcpy_tofs(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
 598         put_fs_byte(0,name->sysname+__OLD_UTS_LEN);
 599         memcpy_tofs(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
 600         put_fs_byte(0,name->nodename+__OLD_UTS_LEN);
 601         memcpy_tofs(&name->release,&system_utsname.release,__OLD_UTS_LEN);
 602         put_fs_byte(0,name->release+__OLD_UTS_LEN);
 603         memcpy_tofs(&name->version,&system_utsname.version,__OLD_UTS_LEN);
 604         put_fs_byte(0,name->version+__OLD_UTS_LEN);
 605         memcpy_tofs(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
 606         put_fs_byte(0,name->machine+__OLD_UTS_LEN);
 607         return 0;
 608 }
 609 
 610 /*
 611  * Only sethostname; gethostname can be implemented by calling uname()
 612  */
 613 asmlinkage int sys_sethostname(char *name, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 614 {
 615         int     i;
 616         
 617         if (!suser())
 618                 return -EPERM;
 619         if (len > __NEW_UTS_LEN)
 620                 return -EINVAL;
 621         for (i=0; i < len; i++) {
 622                 if ((system_utsname.nodename[i] = get_fs_byte(name+i)) == 0)
 623                         return 0;
 624         }
 625         system_utsname.nodename[i] = 0;
 626         return 0;
 627 }
 628 
 629 /*
 630  * Only setdomainname; getdomainname can be implemented by calling
 631  * uname()
 632  */
 633 asmlinkage int sys_setdomainname(char *name, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 634 {
 635         int     i;
 636         
 637         if (!suser())
 638                 return -EPERM;
 639         if (len > __NEW_UTS_LEN)
 640                 return -EINVAL;
 641         for (i=0; i < len; i++) {
 642                 if ((system_utsname.domainname[i] = get_fs_byte(name+i)) == 0)
 643                         return 0;
 644         }
 645         system_utsname.domainname[i] = 0;
 646         return 0;
 647 }
 648 
 649 asmlinkage int sys_getrlimit(unsigned int resource, struct rlimit *rlim)
     /* [previous][next][first][last][top][bottom][index][help] */
 650 {
 651         int error;
 652 
 653         if (resource >= RLIM_NLIMITS)
 654                 return -EINVAL;
 655         error = verify_area(VERIFY_WRITE,rlim,sizeof *rlim);
 656         if (error)
 657                 return error;
 658         put_fs_long(current->rlim[resource].rlim_cur, 
 659                     (unsigned long *) rlim);
 660         put_fs_long(current->rlim[resource].rlim_max, 
 661                     ((unsigned long *) rlim)+1);
 662         return 0;       
 663 }
 664 
 665 asmlinkage int sys_setrlimit(unsigned int resource, struct rlimit *rlim)
     /* [previous][next][first][last][top][bottom][index][help] */
 666 {
 667         struct rlimit new_rlim, *old_rlim;
 668 
 669         if (resource >= RLIM_NLIMITS)
 670                 return -EINVAL;
 671         old_rlim = current->rlim + resource;
 672         new_rlim.rlim_cur = get_fs_long((unsigned long *) rlim);
 673         new_rlim.rlim_max = get_fs_long(((unsigned long *) rlim)+1);
 674         if (((new_rlim.rlim_cur > old_rlim->rlim_max) ||
 675              (new_rlim.rlim_max > old_rlim->rlim_max)) &&
 676             !suser())
 677                 return -EPERM;
 678         *old_rlim = new_rlim;
 679         return 0;
 680 }
 681 
 682 /*
 683  * It would make sense to put struct rusuage in the task_struct,
 684  * except that would make the task_struct be *really big*.  After
 685  * task_struct gets moved into malloc'ed memory, it would
 686  * make sense to do this.  It will make moving the rest of the information
 687  * a lot simpler!  (Which we're not doing right now because we're not
 688  * measuring them yet).
 689  */
 690 int getrusage(struct task_struct *p, int who, struct rusage *ru)
     /* [previous][next][first][last][top][bottom][index][help] */
 691 {
 692         int error;
 693         struct rusage r;
 694         unsigned long   *lp, *lpend, *dest;
 695 
 696         error = verify_area(VERIFY_WRITE, ru, sizeof *ru);
 697         if (error)
 698                 return error;
 699         memset((char *) &r, 0, sizeof(r));
 700         switch (who) {
 701                 case RUSAGE_SELF:
 702                         r.ru_utime.tv_sec = CT_TO_SECS(p->utime);
 703                         r.ru_utime.tv_usec = CT_TO_USECS(p->utime);
 704                         r.ru_stime.tv_sec = CT_TO_SECS(p->stime);
 705                         r.ru_stime.tv_usec = CT_TO_USECS(p->stime);
 706                         r.ru_minflt = p->mm->min_flt;
 707                         r.ru_majflt = p->mm->maj_flt;
 708                         break;
 709                 case RUSAGE_CHILDREN:
 710                         r.ru_utime.tv_sec = CT_TO_SECS(p->cutime);
 711                         r.ru_utime.tv_usec = CT_TO_USECS(p->cutime);
 712                         r.ru_stime.tv_sec = CT_TO_SECS(p->cstime);
 713                         r.ru_stime.tv_usec = CT_TO_USECS(p->cstime);
 714                         r.ru_minflt = p->mm->cmin_flt;
 715                         r.ru_majflt = p->mm->cmaj_flt;
 716                         break;
 717                 default:
 718                         r.ru_utime.tv_sec = CT_TO_SECS(p->utime + p->cutime);
 719                         r.ru_utime.tv_usec = CT_TO_USECS(p->utime + p->cutime);
 720                         r.ru_stime.tv_sec = CT_TO_SECS(p->stime + p->cstime);
 721                         r.ru_stime.tv_usec = CT_TO_USECS(p->stime + p->cstime);
 722                         r.ru_minflt = p->mm->min_flt + p->mm->cmin_flt;
 723                         r.ru_majflt = p->mm->maj_flt + p->mm->cmaj_flt;
 724                         break;
 725         }
 726         lp = (unsigned long *) &r;
 727         lpend = (unsigned long *) (&r+1);
 728         dest = (unsigned long *) ru;
 729         for (; lp < lpend; lp++, dest++) 
 730                 put_fs_long(*lp, dest);
 731         return 0;
 732 }
 733 
 734 asmlinkage int sys_getrusage(int who, struct rusage *ru)
     /* [previous][next][first][last][top][bottom][index][help] */
 735 {
 736         if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
 737                 return -EINVAL;
 738         return getrusage(current, who, ru);
 739 }
 740 
 741 asmlinkage int sys_umask(int mask)
     /* [previous][next][first][last][top][bottom][index][help] */
 742 {
 743         int old = current->fs->umask;
 744 
 745         current->fs->umask = mask & S_IRWXUGO;
 746         return (old);
 747 }

/* [previous][next][first][last][top][bottom][index][help] */