[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Noob libssh question


I can't recall the bug number (I submitted it), but this was an issue until
very recently. It's been fixed, reportedly.

You might build off MASTER, and see if that works better.


Dustin
On Feb 6, 2014 7:22 PM, "craig and heather" <calhjh@xxxxxxxxx> wrote:

> Ok I've now found that waiting in the C program for the runfile to go away
> is the cause of the problem. If I execute a C program that runs start to
> finish without any waiting, ssh_channel_read returns 0 bytes.
>
> So should I check the result from ssh_channel_read and if -2 delay a bit
> and then read it again until the value returned is >= 0?
>
> I thought this was a synchronous function. BTW, I'm using the newest
> version of the library that I downloaded and built today.
>
>
>
>
> On Thu, Feb 6, 2014 at 3:49 PM, craig and heather <calhjh@xxxxxxxxx>wrote:
>
>> Hello,
>>
>> I am using libssl to execute simple C programs between raspberry pi's.
>> These programs are simple SDL graphics applications similar to that listed
>> below that don't write anything to stderr (unless there is an error) or
>> stdout.
>>
>> I am also doing some remote file creation and deletion using the same
>> libssl functionality.
>>
>> When I remotely execute commands such as "touch runfile" or "rm runfile"
>> I can see 0 bytes are returned from ssh_channel_read function as would be
>> expected. However whenever I run one of my little C programs
>> ssh_channel_read always returns -2 but the program runs successfully on the
>> remote system.
>>
>> Is there something I need to do in my C programs to satisfy
>> ssh_channel_read?
>>
>> Thanks for looking
>>
>>
>> /*
>>  * A Smart Screen Module
>>  *
>>  * Sets the entire screen to a specified RGB color
>>  * Typical Call:
>>  *      colorscreen 0 255 0
>>  *
>>  * Concept and Implementation by: Craig A. Lindley
>>  * Last Update: 01/30/2014
>>  */
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <unistd.h>
>> #include <sys/stat.h>
>> #include <sys/types.h>
>>
>> #include "SDL/SDL.h"
>>
>> #define RUN_FILE_NAME "runfile"
>> #define BUSY_FILE_NAME "busy"
>>
>> // Check for file existance
>> int file_exists(char *filename) {
>>
>>     struct stat buffer;
>>     return (stat (filename, &buffer) == 0);
>> }
>>
>> int main (int argc, char* args[]) {
>>
>>     if (argc != 4) {
>>         fprintf(stderr, "Wrong number of arguments\n");
>>         return -1;
>>     }
>>
>>     // Extract RGB values from the command line arguments
>>     int red   = atoi(args[1]);
>>     int green = atoi(args[2]);
>>     int blue  = atoi(args[3]);
>>
>>     // Range check the specified color values
>>     if ((red   < 0) || (red   > 255) ||
>>         (green < 0) || (green > 255) ||
>>         (blue  < 0) || (blue  > 255)) {
>>         fprintf(stderr, "Color values in range 0 <= value < 256\n");
>>         return -1;
>>     }
>>
>>     // Create the busy file
>>     FILE *pFile = fopen (BUSY_FILE_NAME,"w");
>>     if (pFile != NULL) {
>>         fclose(pFile);
>>     }    else    {
>>         fprintf(stderr, "Could not create busy file\n");
>>         return -1;
>>     }
>>
>>     putenv("SDL_FBDEV=/dev/fb1");
>>     putenv("SDL_VIDEODRIVER=fbcon");
>>
>>     // Start SDL
>>     SDL_Init(SDL_INIT_VIDEO);
>>
>>     // Turn off cursor
>>     SDL_ShowCursor(SDL_DISABLE);
>>
>>     const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
>>
>>     int width  = videoInfo->current_w;
>>     int height = videoInfo->current_h;
>>     uint8_t bpp = videoInfo->vfmt->BitsPerPixel;
>>
>>     // Set up screen
>>     SDL_Surface *screen = SDL_SetVideoMode(width, height, bpp,
>> SDL_SWSURFACE);
>>     if (!screen) {
>>         fprintf(stderr, "SDL_SetVideoMode failed\n");
>>         return -1;
>>     }
>>     // Create the specified color
>>     uint32_t color = SDL_MapRGB(screen->format, red, green, blue);
>>
>>     // Create rect the size of the screen
>>     SDL_Rect rect = {0, 0, width, height};
>>
>>     // Fill the screen with the specified color
>>     SDL_FillRect(screen, &rect, color);
>>
>>     // Update Screen
>>     SDL_Flip(screen);
>>
>>     // Pause
>>     SDL_Delay(1000);
>>
>>     // Wait until runfile is gone to terminate
>>     while (file_exists(RUN_FILE_NAME)) {
>>         SDL_Delay(50);
>>     }
>>
>>     // Delete the busy file
>>     if (remove(BUSY_FILE_NAME) != 0) {
>>         fprintf(stderr, "Error deleting busy file\n");
>>     }
>>
>>     // Quit SDL
>>     SDL_Quit();
>>
>>     return 0;
>> }
>>
>>
>> --
>> Craig Lindley
>>
>> If you're one in a million, there are now seven thousand people exactly
>> like you.
>>
>
>
>
> --
> Craig Lindley / Heather Hubbard
>
> New Recordings: craigandheather.net/cnmpage.html
> Latest CD: craigandheather.net/songsilike2013cd.html
>
> Personal Website: craigandheather.net
> Business Website: clockwork.craigandheather.net
> Phone: (719) 495-1873
> Cell: (719) 502-7925
>
> If you're one in a million, there are now seven thousand people exactly
> like you.
>

Follow-Ups:
Re: Noob libssh questionAlan Dunn <amdunn@xxxxxxxxx>
References:
Noob libssh questioncraig and heather <calhjh@xxxxxxxxx>
Re: Noob libssh questioncraig and heather <calhjh@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org