Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1563003
Latest stdio destructor changes was creating a bad problem subtractin…
afxgroup Jan 14, 2025
d0ce9f2
Duplicate IO handles on CreateNewProc
afxgroup Jan 14, 2025
ceeeecb
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Jan 14, 2025
5827b22
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Jan 19, 2025
b6f9bdd
More WINDOWS to LINUX file ending conversion
afxgroup Jan 21, 2025
107cfed
Wrong Printf version requirement printing
afxgroup Jan 28, 2025
bd6b295
Merge branch 'development' of github.com:AmigaLabs/clib4 into line_en…
afxgroup Jan 28, 2025
2f80f55
Get DOSIFace in pthread_create from extern _IDOS
afxgroup Jan 30, 2025
7676191
Merge branch 'afxgroup' of github.com:AmigaLabs/clib4 into afxgroup
afxgroup Jan 30, 2025
989e54f
Added %b format type in printf
afxgroup Feb 8, 2025
ebd6998
Fix on dcngettext was crashing on bindtextdomain and on destructor
afxgroup Feb 9, 2025
03053e5
Added Amiga-1251 charset to iconv
afxgroup Feb 9, 2025
39f9de7
Removed __set_errno from librt since it isn't exported and undefined …
afxgroup Feb 12, 2025
6f9e9d7
Added dlopen example to test shared objects alog rpath and soname
afxgroup Feb 23, 2025
0894c8c
Removed some quirks from dlopen examples
afxgroup Feb 23, 2025
e9e190c
Added static_assert in assert.h
afxgroup Feb 28, 2025
2a0ea0f
Reverted back flock.c changes
afxgroup Feb 28, 2025
11e4d31
Merge branch 'development' of github.com:AmigaLabs/clib4 into afxgroup
afxgroup Feb 28, 2025
52259e3
Changed back (again..) flock.c
afxgroup Feb 28, 2025
4853e6b
Merge branch 'development' of github.com:AmigaLabs/clib4 into afxgroup
afxgroup Feb 28, 2025
06216df
implemented NETBSD getvfsstat function and added an example to test i…
afxgroup Mar 2, 2025
4ed6ea5
Merge branch 'development' of github.com:AmigaLabs/clib4 into afxgroup
afxgroup Mar 2, 2025
c29dac5
__time_delay was not working if wasn't in main thread
afxgroup Mar 6, 2025
1fad70a
Merge branch 'development' of github.com:AmigaLabs/clib4 into afxgroup
afxgroup Mar 6, 2025
c332fbd
Reworked tzset() function. Now parsing of POSIX time zones works corr…
afxgroup Mar 8, 2025
c5b3418
Merge branch 'development' of github.com:AmigaLabs/clib4 into afxgroup
afxgroup Mar 8, 2025
d3d3942
Added baserel support
afxgroup Mar 16, 2025
84d1592
Merge branch 'development' of github.com:AmigaLabs/clib4 into baserel
afxgroup Mar 16, 2025
31a0380
Moved library initialization from _main to libOpen (finally..) now it…
afxgroup Mar 20, 2025
bdcd805
Small changes on constructors when called from a .library
afxgroup Mar 21, 2025
0c1b426
Some small fixes for constructor issues
afxgroup Mar 21, 2025
3aa0409
Fixed a problem on timespec was using 64 bit time and was causing wro…
afxgroup Mar 21, 2025
8f7bd49
Fixed a problem on gettimeofday if ITimer was null
afxgroup Mar 21, 2025
9948863
Changes to fix exe when run from wb
afxgroup Mar 23, 2025
8a31b60
Optimized some string functions
afxgroup Apr 1, 2025
c49a57c
Added backtrace functions
afxgroup Apr 2, 2025
18e26b9
Added dladdr function (not yet finished). Some backtrace refactoring
afxgroup Apr 5, 2025
926ffd9
Added getpriority/setpriority (plus a test example)
afxgroup Apr 13, 2025
5c66835
Merged development changes
afxgroup Apr 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libc.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ C_POSIX := \
wait/waitpid.o \
posix/waitpoll.o \
posix/writev.o \
posix/uname.o
posix/uname.o \
posix/getpriority.o \
posix/setpriority.o

C_REGEX := \
regex/regcomp.o \
Expand Down Expand Up @@ -529,6 +531,7 @@ C_STDLIB := \
stdlib/mprec.o \
stdlib/mulsi3.o \
stdlib/posix_memalign.o \
stdlib/processscan_hook_function.o \
stdlib/program_name.o \
stdlib/putenv.o \
stdlib/qsort.o \
Expand Down
10 changes: 10 additions & 0 deletions library/include/sys/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,20 @@ struct rusage
#define RUSAGE_BOTH (-2) /* sys_wait4() uses this */
#define RUSAGE_THREAD 1 /* only the calling thread */

#define PRIO_MIN (-127)
#define PRIO_MAX 127

#define PRIO_PROCESS 0
#define PRIO_PGRP 1
#define PRIO_USER 2

extern int getrlimit(int resource, struct rlimit *rlp);
extern int setrlimit(int resource, const struct rlimit *rlp);
extern int getrusage(int who, struct rusage *usage);

extern int getpriority (int which, unsigned int who);
extern int setpriority (int which, unsigned int who, int priority);

__END_DECLS

#endif /* _SYS_RESOURCE_H */
34 changes: 34 additions & 0 deletions library/posix/getpriority.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* $Id: resource_getpriority.c,v 1.0 2025-04-13 14:37:27 clib4devs Exp $
*/

#include <sys/resource.h>

#ifndef _STDLIB_HEADERS_H
#include "stdlib_headers.h"
#endif /* _STDLIB_HEADERS_H */

int
getpriority (int which, unsigned int who) {
switch (which) {
case PRIO_PROCESS:
case PRIO_PGRP:
case PRIO_USER: {
struct Hook h = {{NULL, NULL}, (HOOKFUNC) processscan_hook_function, NULL, NULL};

int32 process = ProcessScan(&h, (CONST_APTR) who, 0);
if (process > 0) {
struct Process *cli_process = (struct Process *) process;
return cli_process->pr_Task.tc_Node.ln_Pri;
}
else {
__set_errno(ESRCH);
return -1;
}
break;
}
default:
__set_errno(EINVAL);
return -1;
}
}
14 changes: 1 addition & 13 deletions library/posix/kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@

#include <unistd.h>

static APTR
hook_function(struct Hook *hook, APTR userdata, struct Process *process) {
uint32 pid = (uint32) userdata;
(void) (hook);

if (process->pr_ProcessID == pid) {
return process;
}

return 0;
}

int
kill(pid_t pid, int signal_number) {
struct Process *cli_process;
Expand All @@ -42,7 +30,7 @@ kill(pid_t pid, int signal_number) {
SHOWVALUE(result);
} else {
SHOWMSG("This is a kill for a different process. Search it");
struct Hook h = {{NULL, NULL}, (HOOKFUNC) hook_function, NULL, NULL};
struct Hook h = {{NULL, NULL}, (HOOKFUNC) processscan_hook_function, NULL, NULL};

Forbid();

Expand Down
41 changes: 41 additions & 0 deletions library/posix/setpriority.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* $Id: resource_getpriority.c,v 1.0 2025-04-13 14:37:27 clib4devs Exp $
*/

#include <sys/resource.h>

#ifndef _STDLIB_HEADERS_H
#include "stdlib_headers.h"
#endif /* _STDLIB_HEADERS_H */

int
setpriority (int which, unsigned int who, int priority) {

if (priority < PRIO_MIN || priority > PRIO_MAX) {
__set_errno(EINVAL);
return -1;
}

switch (which) {
case PRIO_PROCESS:
case PRIO_PGRP:
case PRIO_USER: {
struct Hook h = {{NULL, NULL}, (HOOKFUNC) processscan_hook_function, NULL, NULL};

int32 process = ProcessScan(&h, (CONST_APTR) who, 0);
if (process > 0) {
struct Process *cli_process = (struct Process *) process;
SetTaskPri((struct Task *) cli_process, priority);
return 0;
}
else {
__set_errno(ESRCH);
return -1;
}
break;
}
default:
__set_errno(EINVAL);
return -1;
}
}
3 changes: 0 additions & 3 deletions library/pthread/sched_get_priority_max.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@

#include "sched.h"

#define PRIO_MAX 2
#define PRIO_MIN -2

int
sched_get_priority_max(int policy) {
(void) (policy);
Expand Down
3 changes: 0 additions & 3 deletions library/pthread/sched_get_priority_min.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@

#include "sched.h"

#define PRIO_MAX 2
#define PRIO_MIN -2

int sched_get_priority_min(int policy) {
(void) (policy);
return PRIO_MIN;
Expand Down
3 changes: 3 additions & 0 deletions library/shared_library/clib4_vectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -1187,5 +1187,8 @@ static void *clib4Vectors[] = {
(void *) (backtrace_symbols_fd), /* 4432 */
(void *) (dladdr), /* 4436 */

(void *) (getpriority), /* 4440 */
(void *) (setpriority), /* 4444 */

(void *)-1
};
3 changes: 3 additions & 0 deletions library/shared_library/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,9 @@ struct Clib4IFace {
void (* backtrace_symbols_fd) (void *const *buffer, int size, int fd); /* 4432 */
int (* dladdr) (const void *addr, Dl_info *info); /* 4436 */

int (* getpriority) (int which, unsigned int who); /* 4440 */
int (* setpriority) (int which, unsigned int who, int priority); /* 4444 */

};

#ifdef __PIC__
Expand Down
2 changes: 2 additions & 0 deletions library/shared_library/stubs_getpriority.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "stubs_common.h"
Clib4Call(getpriority, 4440);
2 changes: 2 additions & 0 deletions library/shared_library/stubs_setpriority.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "stubs_common.h"
Clib4Call(setpriority, 4444);
19 changes: 19 additions & 0 deletions library/stdlib/processscan_hook_function.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* $Id: stdlib_processscan_hook_function.c,v 1.0 2025-04-17 08:39:45 clib4devs Exp $
*/

#ifndef _STDLIB_HEADERS_H
#include "stdlib_headers.h"
#endif /* _STDLIB_HEADERS_H */

APTR
processscan_hook_function(struct Hook *hook, APTR userdata, struct Process *process) {
uint32 pid = (uint32) userdata;
(void) (hook);

if (process->pr_ProcessID == pid) {
return process;
}

return 0;
}
1 change: 1 addition & 0 deletions library/stdlib/stdlib_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ extern BOOL arg_init();
extern void arg_exit();

extern ULONG amigaos_symbols_callback(struct Hook *hook, struct Task *task, struct SymbolMsg *symbolmsg);
extern APTR processscan_hook_function(struct Hook *hook, APTR userdata, struct Process *process);

#define NAMELEN 32

Expand Down
41 changes: 41 additions & 0 deletions test_programs/misc/priority.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
#include <unistd.h>
#include <errno.h>

int
main(int argc, char *argv[]) {
pid_t pid = getpid(); // Get current process ID
int which = PRIO_PROCESS;
int priority;

// Get the current priority
errno = 0; // Clear errno before calling getpriority
priority = getpriority(which, pid);
if (priority == -1 && errno != 0) {
perror("getpriority");
exit(EXIT_FAILURE);
}

printf("Current priority of process %d: %d\n", pid, priority);

// Set a new priority (nice value)
int new_priority = 10;
if (setpriority(which, pid, new_priority) == -1) {
perror("setpriority");
exit(EXIT_FAILURE);
}

// Confirm the priority was changed
errno = 0;
priority = getpriority(which, pid);
if (priority == -1 && errno != 0) {
perror("getpriority");
exit(EXIT_FAILURE);
}

printf("New priority of process %d: %d\n", pid, priority);

return 0;
}