Skip to content

Commit

Permalink
Some minor close files fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
afxgroup committed Jun 22, 2024
1 parent a88a0a7 commit ac4b060
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 25 deletions.
6 changes: 3 additions & 3 deletions library/c.lib_rev.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define REVISION 0
#define SUBREVISION 0

#define DATE "20.06.2024"
#define DATE "22.06.2024"
#define VERS "clib4.library 1.0.0"
#define VSTRING "clib4.library 1.0.0 (20.06.2024)\r\n"
#define VERSTAG "\0$VER: clib4.library 1.0.0 (20.06.2024)"
#define VSTRING "clib4.library 1.0.0 (22.06.2024)\r\n"
#define VERSTAG "\0$VER: clib4.library 1.0.0 (22.06.2024)"
2 changes: 1 addition & 1 deletion library/crtbegin.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ clib4_start(char *args, int32 arglen, struct Library *sysbase) {
iclib4 = (struct Clib4IFace *) OpenLibraryInterface(iexec, "clib4.library", 1);
if (iclib4 != NULL) {
struct Library *clib4base = ((struct Interface *) iclib4)->Data.LibBase;
if (clib4base->lib_Version == VERSION && clib4base->lib_Revision >= REVISION) {
if (clib4base->lib_Version >= VERSION && clib4base->lib_Revision >= REVISION) {
IClib4 = iclib4;

rc = iclib4->library_start(args, arglen, main, __CTOR_LIST__, __DTOR_LIST__);
Expand Down
2 changes: 1 addition & 1 deletion library/fcntl/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ open(const char *path_name, int open_flag, ... /* mode_t mode */) {
goto out;
}

/* We can open only files, but never directories. */
/* We can open only directories. */
if (!EXD_IS_DIRECTORY(fib)) {
SHOWMSG("we need a directory");

Expand Down
10 changes: 10 additions & 0 deletions library/libc_init_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,26 +411,32 @@ reent_exit(struct _clib4 *__clib4, BOOL fallback) {
/* We can't call close() in fallback reent, since destructors
* are already called and function is no more available */
if (__clib4->randfd[0] >= 0) {
SHOWMSG("Closing randfd[0]");
close(__clib4->randfd[0]);
}

if (__clib4->randfd[1] >= 0) {
SHOWMSG("Closing randfd[1]");
close(__clib4->randfd[1]);
}
}

/* Free wchar stuff */
if (__clib4->wide_status != NULL) {
SHOWMSG("Freeing wide_status");
FreeVec(__clib4->wide_status);
__clib4->wide_status = NULL;
}
/* Remove random semaphore */
SHOWMSG("Delete __random_lock semaphore");
__delete_semaphore(__clib4->__random_lock);
/* Remove pipe semaphore */
SHOWMSG("Delete __pipe_semaphore semaphore");
__delete_semaphore(__clib4->__pipe_semaphore);
if (!fallback) { //TODO : Freeing memalign crash libExpunge and I don't know why
/* Free memalign stuff */
if (__clib4->__memalign_pool) {
SHOWMSG("Freeing memalign pool");
/* Check if we have something created with posix_memalign and not freed yet.
* But this is a good point also to free something allocated with memalign or
* aligned_alloc and all other functions are using memalign_tree to allocate memory
Expand All @@ -452,18 +458,22 @@ reent_exit(struct _clib4 *__clib4, BOOL fallback) {
}

FreeSysObject(ASOT_ITEMPOOL, __clib4->__memalign_pool);
SHOWMSG("Done");
}
}
/* Free dl stuff */
struct ElfIFace *IElf = __IElf;

if (IElf && __clib4->__dl_root_handle != NULL) {
SHOWMSG("Closing __dl_root_handle");
CloseElfTags(__clib4->__dl_root_handle, CET_ReClose, TRUE, TAG_DONE);
__clib4->__dl_root_handle = NULL;
SHOWMSG("Done");
}

FreeVec(__clib4);
__clib4 = NULL;
SHOWMSG("__clib4 destroyed correctly");
}
}

Expand Down
12 changes: 7 additions & 5 deletions library/posix/raise.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ raise(int sig) {
goto out;
}
else {
SHOWMSG("calling the handler");
(*handler)(sig);
if (*handler != NULL) {
SHOWMSG("calling the handler");
(*handler)(sig);

if (sig == SIGINT || sig == SIGTERM || sig == SIGKILL)
SetSignal(0, SIGBREAKF_CTRL_C);
if (sig == SIGINT || sig == SIGTERM || sig == SIGKILL)
SetSignal(0, SIGBREAKF_CTRL_C);

SHOWMSG("done.");
SHOWMSG("done.");
}
}

/* Unblock signal delivery again. */
Expand Down
1 change: 0 additions & 1 deletion library/socket/select_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,6 @@ __select(int num_fds, fd_set *read_fds, fd_set *write_fds, fd_set *except_fds, s
else if (FLAG_IS_SET(fd->fd_Flags, FDF_TERMIOS)) {
SHOWVALUE("FLAG_IS_SET(fd->fd_Flags, FDF_TERMIOS");
struct termios *tios = fd->fd_Aux;
SHOWVALUE(FLAG_IS_CLEAR(tios->c_lflag, ICANON));

if (WaitForChar(readFile, 1)) {
got_input = TRUE;
Expand Down
6 changes: 3 additions & 3 deletions library/stdio/file_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ FILE_CONSTRUCTOR(stdio_file_init) {
case STDERR_FILENO:
default:

iob_flags = IOBF_IN_USE | IOBF_WRITE | IOBF_NO_NUL | IOBF_BUFFER_MODE_NONE;
fd_flags = FDF_IN_USE | FDF_WRITE;
default_file = BZERO;
iob_flags = IOBF_IN_USE | IOBF_WRITE | IOBF_NO_NUL | IOBF_BUFFER_MODE_LINE;
fd_flags = FDF_IN_USE | FDF_WRITE | FDF_NO_CLOSE | FDF_IS_INTERACTIVE;
default_file = ErrorOutput();
break;
}

Expand Down
8 changes: 1 addition & 7 deletions library/stdio/flockfile.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: stdio_flockfile.c,v 1.4 2006-01-08 12:04:24 clib4devs Exp $
* $Id: stdio_flockfile.c,v 1.5 2024-06-19 12:04:24 clib4devs Exp $
*/

#ifndef _STDIO_HEADERS_H
Expand All @@ -10,11 +10,6 @@ void
flockfile(FILE *stream) {
struct iob *file = (struct iob *) stream;

ENTER();
SHOWPOINTER(stream);

assert(stream != NULL);

__check_abort();

if (stream == NULL) {
Expand All @@ -39,6 +34,5 @@ flockfile(FILE *stream) {
}

out:
LEAVE();
return;
}
12 changes: 8 additions & 4 deletions library/stdio/init_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ __close_all_files(struct _clib4 *__clib4) {
if (__clib4->__num_iob > 0) {
for (i = 0; i < __clib4->__num_iob; i++) {
if (FLAG_IS_SET(__clib4->__iob[i]->iob_Flags, IOBF_IN_USE)) {
D(("Close __iob %ld\n", i));
fclose((FILE *) __clib4->__iob[i]);
__clib4->__num_iob--;
}
}

__clib4->__num_iob = 0;
}

if (__clib4->__num_fd > 0) {
for (i = 0; i < __clib4->__num_fd; i++) {
/* If file is set as in use close it only if it isn't marked as FDF_NO_CLOSE */
if (FLAG_IS_SET(__clib4->__fd[i]->fd_Flags, FDF_IN_USE) && FLAG_IS_CLEAR(__clib4->__fd[i]->fd_Flags, FDF_NO_CLOSE)) {
D(("Close __fd %ld\n", i));
close(i);
UnlockMem(__clib4->__fd[i], sizeof(*__clib4->__fd[i]));
__clib4->__num_fd--;
}
else {
D(("Can't close __fd %d FDF_IN_USE=%d FDF_NO_CLOSE=%d \n", i, FLAG_IS_SET(__clib4->__fd[i]->fd_Flags, FDF_IN_USE), FLAG_IS_SET(__clib4->__fd[i]->fd_Flags, FDF_NO_CLOSE)));
}
UnlockMem(__clib4->__fd[i], sizeof(*__clib4->__fd[i]));
}
__clib4->__num_fd = 0;
}

__stdio_unlock(__clib4);
Expand Down
3 changes: 3 additions & 0 deletions library/stdlib/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,14 @@ _main(

SHOWMSG("Calling reent_exit on _clib4");
reent_exit(__clib4, FALSE);
SHOWMSG("Done");

if (sms) {
Forbid();
ReplyMsg(&sms->sm_Message);
}

SHOWMSG("Exit from _main");

return rc;
}

0 comments on commit ac4b060

Please sign in to comment.