From: Simone Piccardi Date: Mon, 14 Jun 2010 10:39:55 +0000 (+0000) Subject: Correzioni ai valori di ritorno di setpriority e sched_setscheduler, X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=commitdiff_plain;h=673a0c6b1a7cc3d077cdaf4d54fab5e38e453ca3;p=gapil.git Correzioni ai valori di ritorno di setpriority e sched_setscheduler, come segnalato Francesco Cosoleto. Aggiunta del programma di impostazione delle quote disco. --- diff --git a/prochand.tex b/prochand.tex index 7fe061f..ad90d7e 100644 --- a/prochand.tex +++ b/prochand.tex @@ -2492,8 +2492,8 @@ impostare la priorit {int setpriority(int which, int who, int prio)} Imposta la priorità per l'insieme dei processi specificati. - \bodydesc{La funzione ritorna la priorità in caso di successo e -1 in caso di - errore, nel qual caso \var{errno} può assumere i valori: + \bodydesc{La funzione ritorna 0 in caso di successo e -1 in caso di errore, + nel qual caso \var{errno} può assumere i valori: \begin{errlist} \item[\errcode{ESRCH}] non c'è nessun processo che corrisponda ai valori di \param{which} e \param{who}. @@ -2610,8 +2610,8 @@ la funzione {int sched\_setscheduler(pid\_t pid, int policy, const struct sched\_param *p)} Imposta priorità e politica di scheduling. - \bodydesc{La funzione ritorna la priorità in caso di successo e $-$1 in caso - di errore, nel qual caso \var{errno} può assumere i valori: + \bodydesc{La funzione ritorna 0 in caso di successo e $-$1 in caso di + errore, nel qual caso \var{errno} può assumere i valori: \begin{errlist} \item[\errcode{ESRCH}] il processo \param{pid} non esiste. \item[\errcode{EINVAL}] il valore di \param{policy} non esiste o il @@ -2653,7 +2653,7 @@ per \param{policy} mantiene la politica di scheduling corrente. \label{tab:proc_sched_policy} \end{table} -\footnotetext[41]{introdotto con il kernel 2.6.16.} +\footnotetext[44]{introdotto con il kernel 2.6.16.} \footnotetext{introdotto con il kernel 2.6.23.} Con le versioni più recenti del kernel sono state introdotte anche delle diff --git a/sources/mygetquota.c b/sources/mygetquota.c index 82e7e9e..db4311a 100644 --- a/sources/mygetquota.c +++ b/sources/mygetquota.c @@ -91,10 +91,10 @@ int main(int argc, char *argv[]) uid = atoi(argv[optind]); ret = quotactl(QCMD(Q_GETQUOTA,who), argv[optind+1], uid, (caddr_t) &dq); if (!ret) { - printf("Data:%7.1qu\n", dq.dqb_curspace); - printf("Soft:%7.1qu\tHard: %7.1qu\tGrace: %7.1qu\n", dq.dqb_bsoftlimit, dq.dqb_bhardlimit, dq.dqb_btime); + printf("Data:%lld\n", dq.dqb_curspace); + printf("Soft:%lld\tHard: %lld\tGrace: %lld\n", dq.dqb_bsoftlimit, dq.dqb_bhardlimit, dq.dqb_btime); printf("Files: %7.1qu\n", dq.dqb_curinodes); - printf("Soft: %7.1qu\tHard: %7.1qu\tGrace: %7.1qu\n", dq.dqb_isoftlimit, dq.dqb_ihardlimit, dq.dqb_itime); + printf("Soft: %lld\tHard: %lld\tGrace: %lld\n", dq.dqb_isoftlimit, dq.dqb_ihardlimit, dq.dqb_itime); } else perror("errore"); exit(0); diff --git a/sources/mysetquota.c b/sources/mysetquota.c new file mode 100644 index 0000000..bfc9a3d --- /dev/null +++ b/sources/mysetquota.c @@ -0,0 +1,141 @@ +/* mysetquota.c + * + * Copyright (C) 2010 Simone Piccardi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/***************************************************************************** + * + * File mysetquota.c: An example for quotactl function + * + * Author: S. Piccardi Jun. 2010 + * + *****************************************************************************/ +#include /* C strings library */ +#include /* primitive system data types */ +#include /* file characteristics constants and functions */ +#include /* unix standard library */ +#include /* C standard library */ +#include /* standard I/O library */ +#include + +/* + * Program mysetquota + * + * Use quotactl to set an user quota + */ + +/* Help printing routine */ +void usage(void); +void printquota(struct dqblk dq); + +int main(int argc, char *argv[]) +{ +/* + * Variables definition + */ + int i,j,ret; + int who=USRQUOTA; + uid_t uid=0; + struct dqblk dq; + /* + * Input section: decode command line parameters + * Use getopt function + */ + opterr = 0; /* don't want writing to stderr */ + while ( (i = getopt(argc, argv, "hgu")) != -1) { + switch (i) { + /* + * Handling options + */ + case 'h': /* help option */ + usage(); + break; + case 'g': /* group option */ + who=GRPQUOTA; + break; + case 'u': /* user option */ + who=USRQUOTA; + break; + case '?': /* unrecognized options */ + printf("Unrecognized options -%c\n",optopt); + usage(); + default: /* should not reached */ + usage(); + } + } + /* *********************************************************** + * + * Options processing completed + * + * Main code beginning + * + * ***********************************************************/ + /* remaining argument check */ + if ((argc - optind) != 6) { + printf("Wrong number of arguments %d\n", argc - optind); + usage(); + } + /* main body */ + ret = quotactl(QCMD(Q_GETQUOTA,who), argv[optind+1], uid, (caddr_t) &dq); + if (!ret) { + printf("Previous values\n"); + printquota(dq); + } else { + perror("errore"); + exit(1); + } + + uid = atoi(argv[optind]); + dq.dqb_bsoftlimit = atoi(argv[optind+2]); + dq.dqb_bhardlimit = atoi(argv[optind+3]); + dq.dqb_isoftlimit = atoi(argv[optind+4]); + dq.dqb_ihardlimit = atoi(argv[optind+5]); + dq.dqb_valid = QIF_LIMITS; + ret = quotactl(QCMD(Q_SETQUOTA,who), argv[optind+1], uid, (caddr_t) &dq); + if (!ret) { + ret = quotactl(QCMD(Q_GETQUOTA,who), argv[optind+1], uid, (caddr_t) &dq); + if (!ret) { + printf("After values\n"); + printquota(dq); + } else { + perror("errore in rilettura"); + exit(1); + } + } else { + perror("errore in scrittura"); + exit(1); + } + + +} +/* + * routine to print usage info and exit + */ +void usage(void) { + printf("Program mysetquota: set an user quota \n"); + printf("Usage:\n"); + printf("mysetquota [-u|-g] uid filesystem \n"); + exit(1); +} + +void printquota(struct dqblk dq) +{ + printf("Data:%lld\n", dq.dqb_curspace); + printf("Soft:%lld\tHard: %lld\tGrace: %lld\n", dq.dqb_bsoftlimit, dq.dqb_bhardlimit, dq.dqb_btime); + printf("Files: %lld\n", dq.dqb_curinodes); + printf("Soft: %lld\tHard: %lld\tGrace: %lld\n", dq.dqb_isoftlimit, dq.dqb_ihardlimit, dq.dqb_itime); + +}