From bdfab104185d733c7bca429bf14454cd076f6a5d Mon Sep 17 00:00:00 2001 From: Sergii Stoian Date: Mon, 12 Aug 2024 02:19:35 +0300 Subject: [PATCH] Login: fixed sessionLog var memory allocation. --- Applications/Login/Controller.m | 5 ++-- Applications/Login/UserSession.m | 45 ++++++++++++++------------------ 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/Applications/Login/Controller.m b/Applications/Login/Controller.m index 094aeb2a..60c073f3 100644 --- a/Applications/Login/Controller.m +++ b/Applications/Login/Controller.m @@ -67,6 +67,7 @@ - (void)openSessionForUser:(NSString *)user @autoreleasepool { while (aSession.isRunning != NO) { [aSession launchSessionScript]; + NSLog(@"Session Log (openSessionForUser:) - %@", aSession.sessionLog); [self performSelectorOnMainThread:@selector(userSessionWillClose:) withObject:aSession waitUntilDone:YES]; @@ -103,7 +104,7 @@ - (NSInteger)runAlertPanelForSession:(UserSession *)session [alert setButtonsTarget:self]; [alert setButtonsAction:@selector(alertButtonPressed:)]; - consoleLogPath = [session.sessionLog copy]; + consoleLogPath = session.sessionLog; NSLog(@"Console log for %@ - %@", session.userName, session.sessionLog); [alert show]; @@ -166,7 +167,7 @@ - (void)userSessionWillClose:(UserSession *)session // "Do you want to restart or cleanup session?\n" // "Note: \"Cleanup\" will kill all running applications.", // @"Restart", @"Cleanup", nil); - choice = [self runAlertPanelForSession:session]; + choice = [self runAlertPanelForSession:session]; if (choice == NSAlertAlternateReturn) { [self closeAllXClients]; } diff --git a/Applications/Login/UserSession.m b/Applications/Login/UserSession.m index 3d9f94ab..d5800699 100644 --- a/Applications/Login/UserSession.m +++ b/Applications/Login/UserSession.m @@ -37,29 +37,18 @@ @implementation UserSession // Log file for session use -- (void)_setupSessionLog -{ - NSFileManager *fm = [NSFileManager defaultManager]; - NSString *logDir; - NSString *logPath; - BOOL isDir; - - logDir = [NSString stringWithFormat:@"/tmp/GNUstepSecure%u", - getpwnam([_userName cString])->pw_uid]; - - if (![fm fileExistsAtPath:logDir isDirectory:&isDir]) { - [fm createDirectoryAtPath:logDir - withIntermediateDirectories:YES - attributes:@{NSFilePosixPermissions:@"700"} - error:0]; - } - if (_sessionLog != nil) { - [_sessionLog release]; - } - logPath = [logDir stringByAppendingPathComponent:@"console.log"]; - _sessionLog = [[NSString alloc] initWithString:logPath]; - NSLog(@"Session log for %@ - %@", _userName, _sessionLog); -} +// - (NSString *)_sessionLogPath +// { +// struct passwd *user; +// NSString *logPath; + +// user = getpwnam([_userName cString]); +// if (user) { +// logPath = [[NSString alloc] initWithFormat:@"/tmp/GNUstepSecure%u/console.log", user->pw_uid]; +// } + +// return logPath; +// } // Called for every launched command (launchCommand:) - (BOOL)_setUserEnvironment @@ -102,8 +91,8 @@ - (BOOL)_setUserEnvironment // Create user GNUstep directory in /tmp. [[NSFileManager defaultManager] - createDirectoryAtPath:[NSString stringWithFormat:@"/tmp/GNUstepSecure%d", user->pw_uid] - attributes:@{@"NSFilePosixPermissions":[NSNumber numberWithShort:0700]}]; + createDirectoryAtPath:[NSString stringWithFormat:@"/tmp/GNUstepSecure%d", user->pw_uid] + attributes:@{@"NSFilePosixPermissions" : [NSNumber numberWithShort:0700]}]; // General environment variables setenv("USER", user->pw_name, 1); @@ -126,7 +115,7 @@ - (BOOL)_setUserEnvironment // For CoreFoundation dynamic loading of CFNetwork setenv("CFNETWORK_LIBRARY_PATH", "/usr/NextSpace/lib/libCFNetwork.so", 1); - [self _setupSessionLog]; + // [self _setupSessionLog]; setenv("NS_LOGFILE", [_sessionLog cString], 1); return YES; @@ -162,6 +151,10 @@ - (id)initWithOwner:(Controller *)controller _userName = [[NSString alloc] initWithString:name]; + // _sessionLog = [self _sessionLogPath]; + _sessionLog = [[NSString alloc] + initWithFormat:@"/tmp/GNUstepSecure%u/console.log", getpwnam([_userName cString])->pw_uid]; + return self; }