Skip to content

Commit 72a9f34

Browse files
authored
macOS fixes, bump year
Fixed so app works on macOS properly and bumped year to 2022. * fixed breakdown of connection so VNC is closed first, then SSH (when applicable)
1 parent e7782ce commit 72a9f34

File tree

9 files changed

+63
-98
lines changed

9 files changed

+63
-98
lines changed

src/app.cxx

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* app.cxx - part of SpiritVNC - FLTK
3-
* 2016-2021 Will Brokenbourgh https://www.pismotek.com/brainout/
3+
* 2016-2022 Will Brokenbourgh https://www.pismotek.com/brainout/
44
*/
55

66
/*
@@ -2009,6 +2009,7 @@ void svHandleThreadConnection (void * data)
20092009
itm->icon = app->iconDisconnectedBigError;
20102010
else
20112011
itm->icon = app->iconNoConnect;
2012+
20122013
svHandleListItemIconChange(NULL);
20132014

20142015
if (itm->isListener == true)
@@ -2079,27 +2080,6 @@ void svHandleThreadCursorChange (void * notUsed)
20792080
}
20802081

20812082

2082-
void svHandlePKill (void * itmData)
2083-
{
2084-
HostItem * itm = static_cast<HostItem *>(itmData);
2085-
2086-
if (itm == NULL)
2087-
return;
2088-
2089-
std::string sshKillCommand;
2090-
int sshKillResult = -1;
2091-
2092-
if (itm->sshCommandLine == "")
2093-
return;
2094-
2095-
sshKillCommand = "pkill --full \"" + itm->sshCommandLine + "\"";
2096-
//printf("%s\n", sshKillCommand.c_str());
2097-
sshKillResult = system(sshKillCommand.c_str());
2098-
(void)sshKillResult;
2099-
//printf("Result: %i\n", sshKillResult);
2100-
}
2101-
2102-
21032083
/* create and insert empty listitem if no items were added at startup */
21042084
void svInsertEmptyItem ()
21052085
{

src/app.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* app.h - part of SpiritVNC - FLTK
3-
* 2016-2021 Will Brokenbourgh https://www.pismotek.com/brainout/
3+
* 2016-2022 Will Brokenbourgh https://www.pismotek.com/brainout/
44
*/
55

66
/*
@@ -262,6 +262,7 @@ class SVSecretInput : public Fl_Secret_Input
262262

263263
/* forward function declarations */
264264
void svCloseChildWindow (Fl_Widget *, void *);
265+
void svCloseSSHConnection (void *);
265266
void svConfigCreateNew ();
266267
void svConfigReadCreateHostList ();
267268
void svConfigWrite ();
@@ -270,7 +271,6 @@ void svCreateAppIcons (bool fromAppOptions = false);
270271
std::string svConvertBooleanToString (bool);
271272
bool svConvertStringToBoolean (const std::string&);
272273
void svCreateGUI ();
273-
void * svCreateSSHConnection(void *);
274274
void svDebugLog (const std::string&);
275275
void svDeleteItem (int);
276276
void svDeselectAllItems ();
@@ -283,7 +283,6 @@ void svHandleLocalClipboard (int, void *);
283283
void svHandleHostListButtons (Fl_Widget *, void *);
284284
void svHandleHostListEvents (Fl_Widget *, void *);
285285
void svHandleMainWindowEvents (Fl_Widget *, void *);
286-
void svHandlePKill (void *);
287286
void svPositionWidgets ();
288287
void svHandleListItemIconChange (void * notUsed);
289288
void svHandleThreadConnection (void *);

src/consts_enums.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* consts_enums.h - part of SpiritVNC - FLTK
3-
* 2016-2021 Will Brokenbourgh https://www.pismotek.com/brainout/
3+
* 2016-2022 Will Brokenbourgh https://www.pismotek.com/brainout/
44
*/
55

66
/*
@@ -38,7 +38,7 @@
3838
/* constants */
3939
#define SV_APP_VERSION "0.4.8"
4040

41-
#define SV_CURRENT_YEAR "2021"
41+
#define SV_CURRENT_YEAR "2022"
4242

4343
#define SV_CONNECTION_TIMEOUT_SECS 30
4444
#15

src/hostitem.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* hostitem.h - part of SpiritVNC - FLTK
3-
* 2016-2021 Will Brokenbourgh https://www.pismotek.com/brainout/
3+
* 2016-2022 Will Brokenbourgh https://www.pismotek.com/brainout/
44
*/
55

66
/*
@@ -85,8 +85,8 @@ class HostItem
8585
hasEnded(false),
8686
icon(NULL),
8787
lastErrorMessage(""),
88-
sshCommandLine(""),
89-
sshWaitTime(5)
88+
sshWaitTime(5),
89+
sshCmdStream(NULL)
9090
{}
9191

9292
std::string name;
@@ -128,8 +128,8 @@ class HostItem
128128
bool hasEnded;
129129
Fl_Image * icon;
130130
std::string lastErrorMessage;
131-
std::string sshCommandLine;
132131
int sshWaitTime;
132+
FILE * sshCmdStream;
133133
};
134134

135135
#endif

src/spiritvnc.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* spiritvnc.cxx - part of SpiritVNC - FLTK
3-
* 2016-2021 Will Brokenbourgh https://www.pismotek.com/brainout/
3+
* 2016-2022 Will Brokenbourgh https://www.pismotek.com/brainout/
44
*
55
* To God be the glory! In Jesus name! :-D
66
*

src/ssh.cxx

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ssh.cxx - part of SpiritVNC - FLTK
3-
* 2016-2021 Will Brokenbourgh https://www.pismotek.com/brainout/
3+
* 2016-2022 Will Brokenbourgh https://www.pismotek.com/brainout/
44
*/
55

66
/*
@@ -34,90 +34,79 @@
3434

3535
#include "app.h"
3636
#include "hostitem.h"
37-
#include "ssh.h"
3837

39-
#include <pthread.h>
4038

39+
/* close and clean up ssh connection */
40+
void svCloseSSHConnection (void * itmData)
41+
{
42+
HostItem * itm = static_cast<HostItem *>(itmData);
4143

42-
//#include <array>
43-
44-
45-
//void sshExec(const char * cmd, HostItem * itm)
46-
//{
47-
//char buffer[128];
48-
49-
//FILE * pipe = popen(cmd, "r");
50-
51-
//if (!pipe) //throw std::runtime_error("popen() failed!");
52-
//return;
53-
54-
//while (fgets(buffer, sizeof buffer, pipe) != NULL)
55-
//{
56-
//itm->sshCommandOutput.append(buffer);
57-
//}
44+
if (itm == NULL || itm->sshCmdStream == NULL)
45+
return;
5846

59-
//pclose(pipe);
47+
int sshKillResult = -1;
48+
49+
fprintf(itm->sshCmdStream, "%s\n", "exit");
50+
fflush(itm->sshCmdStream);
51+
52+
sshKillResult = pclose(itm->sshCmdStream);
6053

61-
//return;
62-
//}
54+
(void)sshKillResult;
55+
}
6356

6457

6558
/* create ssh session and ssh forwarding */
66-
/* (this is called as a thread because it blocks) */
67-
void * svCreateSSHConnection (void * data)
59+
void svCreateSSHConnection (void * data)
6860
{
69-
pthread_detach(pthread_self());
70-
61+
std::string sshCommandLine;
7162
std::string strError;
7263

7364
HostItem * itm = static_cast<HostItem *>(data);
7465

7566
if (itm == NULL)
76-
return SV_RET_VOID;
67+
return;
7768

78-
std::string sshCheck = "which " + app->sshCommand + " > /dev/null";
69+
std::string sshCheck = "which " + app->sshCommand + "5 > /dev/null";
7970

8071
// first check to see if the ssh command is working
8172
if (system(sshCheck.c_str()) != 0)
8273
{
8374
fl_beep(FL_BEEP_DEFAULT);
84-
svMessageWindow("Error: The SSH command doesn't work.\n\nCheck that the SSH client "
85-
"is installed", "SpiritVNC - FLTK");
75+
svMessageWindow("Error: This connection requires SSH and \nthe SSH command isn't working."
76+
"\n\nCheck that the SSH client program is installed", "SpiritVNC - FLTK");
8677

8778
svLogToFile("SSH command not working for connection '"
8879
+ itm->name + "' - " + itm->hostAddress);
80+
81+
itm->lastErrorMessage = "SSH command not working";
8982

9083
itm->sshReady = false;
9184
itm->hasError = true;
9285

93-
return SV_RET_VOID;
86+
return;
9487
}
9588

9689
// build the command string for our system() call
97-
itm->sshCommandLine = app->sshCommand + " " + itm->sshUser + "@" + itm->hostAddress + " -N" +
90+
sshCommandLine = app->sshCommand + " " + itm->sshUser + "@" + itm->hostAddress + " -t" + " -t" + //" -N" +
9891
" -p " + itm->sshPort +
9992
" -L " + std::to_string(itm->sshLocalPort) + ":127.0.0.1:" + itm->vncPort +
10093
" -i " + itm->sshKeyPrivate;
10194

102-
// (over-)optimistically declare that ssh is ready
103-
itm->sshReady = true;
104-
10595
// call the system's ssh client, if available
106-
if (system(itm->sshCommandLine.c_str()) != -1)
107-
{
108-
svLogToFile("SSH connection disconnected normally from '"
109-
+ itm->name + "' - " + itm->hostAddress);
110-
111-
itm->sshReady = false;
112-
}
96+
itm->sshCmdStream = popen(sshCommandLine.c_str(), "w");
97+
98+
if (itm->sshCmdStream != NULL)
99+
// ssh started okay
100+
itm->sshReady = true;
113101
else
114102
{
103+
// something -- happened
115104
svLogToFile("SSH connection disconnected abnormally from '"
116105
+ itm->name + "' - " + itm->hostAddress);
117106

118107
itm->sshReady = false;
119108
itm->hasError = true;
120109
}
121110

122-
return SV_RET_VOID;
111+
return;
123112
}

src/ssh.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ssh.h - part of SpiritVNC - FLTK
3-
* 2016-2021 Will Brokenbourgh https://www.pismotek.com/brainout/
3+
* 2016-2022 Will Brokenbourgh https://www.pismotek.com/brainout/
44
*/
55

66
/*
@@ -35,7 +35,7 @@
3535
#ifndef SSH_H
3636
#define SSH_H
3737

38-
//void sshExec(const char * cmd);
39-
void * svCreateSSHConnection (void *);
38+
void svCloseSSHConnection (void *);
39+
void svCreateSSHConnection (void *);
4040

4141
#endif

src/vnc.cxx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* vnc.cxx - part of SpiritVNC - FLTK
3-
* 2016-2021 Will Brokenbourgh https://www.pismotek.com/brainout/
3+
* 2016-2022 Will Brokenbourgh https://www.pismotek.com/brainout/
44
*/
55

66
/*
@@ -166,7 +166,7 @@ void VncObject::createVNCObject (HostItem * itm)
166166
itm->hasError = true;
167167

168168
svLogToFile("ERROR - Could not open the private SSH key file");
169-
svMessageWindow("Could not open the private SSH key "
169+
svMessageWindow("Error: Could not open the private SSH key "
170170
"file for '" + itm->name + "' - " + itm->hostAddress);
171171

172172
if (vnc->vncClient != NULL)
@@ -184,9 +184,11 @@ void VncObject::createVNCObject (HostItem * itm)
184184
svDebugLog("svCreateVNCObject - Creating and running threadSSH");
185185

186186
// create, launch and detach call to create our ssh connection
187-
int sshResult = pthread_create(&itm->threadSSH, NULL, svCreateSSHConnection, itm);
187+
//int sshResult = pthread_create(&itm->threadSSH, NULL, svCreateSSHConnection, itm);
188+
svCreateSSHConnection(itm);
188189

189-
if (sshResult != 0)
190+
//if (sshResult != 0)
191+
if (itm->sshReady == false)
190192
{
191193
svLogToFile("ERROR - Couldn't create SSH thread for '" + itm->name +
192194
"' - " + itm->hostAddress);
@@ -222,8 +224,7 @@ void VncObject::createVNCObject (HostItem * itm)
222224
itm->isConnecting = false;
223225
itm->hasCouldntConnect = true;
224226

225-
if (itm->sshCommandLine != "")
226-
svHandlePKill(itm);
227+
svCloseSSHConnection(itm);
227228

228229
svHandleThreadConnection(itm);
229230

@@ -235,9 +236,7 @@ void VncObject::createVNCObject (HostItem * itm)
235236
svDebugLog("svCreateVNCObject - Creating and running itm->threadRFB");
236237

237238
// create, launch and detach call to create our vnc connection
238-
int rfbResult = pthread_create(&itm->threadRFB, NULL, VncObject::initVNCConnection, itm);
239-
240-
if (rfbResult != 0)
239+
if (pthread_create(&itm->threadRFB, NULL, VncObject::initVNCConnection, itm) != 0)
241240
{
242241
svLogToFile("ERROR - Couldn't create RFB thread for '" + itm->name +
243242
"' - " + itm->hostAddress);
@@ -350,23 +349,21 @@ void VncObject::endViewer ()
350349
itm->threadRFBRunning = false;
351350
}
352351

353-
// tell ssh to clean up if a ssh/vnc connection
354-
if (itm->hostType == 's')
355-
{
356-
itm->sshReady = false;
357-
358-
if (itm->sshCommandLine != "")
359-
svHandlePKill(itm);
360-
//Fl::awake(svHandlePKill, itm);
361-
}
362-
363352
itm->isConnected = false;
364353
itm->isConnecting = false;
365354
itm->hasDisconnectRequest = false;
366355
itm->hasEnded = true;
367356

368357
// clean up the client
369358
rfbClientCleanup(vncClient);
359+
360+
// tell ssh to clean up if a ssh/vnc connection
361+
if (itm->hostType == 's')
362+
{
363+
itm->sshReady = false;
364+
365+
svCloseSSHConnection(itm);
366+
}
370367
}
371368
}
372369

src/vnc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* vnc.h - part of SpiritVNC - FLTK
3-
* 2016-2021 Will Brokenbourgh https://www.pismotek.com/brainout/
3+
* 2016-2022 Will Brokenbourgh https://www.pismotek.com/brainout/
44
*/
55

66
/*

0 commit comments

Comments
 (0)